PHP symfony FOSElastica
June 6, 2022
June 6, 2022

fos_elastica:
2 default_manager: orm
3 clients:
4 default: { host: 'localhost', port: '9200' }
5 indexes:
6 sample:
7 properties:
8 id:
9 type: integer
10 name:
11 type: keyword
12 persistence:
13 model: ....\Sample
14 repository: ....\SampleElasticSearchRepository
15 finder: ~
16 provider:
See the problem:
fos_elastica:
2 default_manager: orm
3 clients:
4 default: { host: 'localhost', port: '9200' }
5 indexes:
6 sample:
7 properties:
8 id:
9 type: integer
10 name:
11 type: keyword
12 persistence:
13 persister:
14 refresh: wait_for
15 model: ....\Sample
16 repository: ....\SampleElasticSearchRepository
17 finder: ~
18 provider: ~
For the end:
Visit ElasticSearch documentation for refresh option: https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-refresh.html
Visit Github issue for FOSElastica: https://github.com/FriendsOfSymfony/FOSElasticaBundle/issues/1516
Visit source code for FOSElastica (Please to see lines 363 to 373) https://github.com/jvasseur/FOSElasticaBundle/blob/4075aa439febb0280262c7e76fe33bbd4379cf86/src/DependencyInjection/Configuration.php
curl -X DELETE 'http://localhost:9200/sampleslist all indexes
curl -X GET 'http://localhost:9200/_cat/indices?v'list all docs in index
curl -X GET 'http://localhost:9200/sample/_search'query using URL parameters
Here we use Lucene query format to write q=school:Harvard. curl -X GET http://localhost:9200/samples/_search?q=school:Harvarlist index mapping All Elasticsearch fields are indexes. So this lists all fields and their types in an index.
curl -X GET http://localhost:9200/samplesAdd Data
curl -XPUT --header 'Content-Type: application/json' http://localhost:9200/samples/_doc/1 -d '{
"school" : "Harvard"
}'
Update Doc
Here is how to add fields to an existing document. First we create a new one. Then we update it.
curl -XPUT --header 'Content-Type: application/json' http://localhost:9200/samples/_doc/2 -d '
{
"school": "Clemson"
}'
curl -XPOST --header 'Content-Type: application/json' http://localhost:9200/samples/_doc/2/_update -d '{
"doc" : {
"students": 50000}
}'
backup index
curl -XPOST --header 'Content-Type: application/json' http://localhost:9200/_reindex -d '{
"source": {
"index": "samples"
},
"dest": {
"index": "samples_backup"
}
}'
Bulk load data in JSON format
export pwd="elastic:" curl --user $pwd -H 'Content-Type: application/x-ndjson' -XPOST 'https://58571402f5464923883e7be42a037917.eu-central-1.aws.cloud.es.io:9243/0/_bulk?pretty' --data-binary @<file>