Elasticsearch Tutorial For Beginners – create index add documents and searching

root@pve-02-ubuntu-2:~# vi test.json
{ „index“:{„_index“:“schools“, „_type“:“school“, „_id“:“1″ }}
{ „name“:“Central School“, „description“:“CBSE Affiliation“, „street“:“Nagan“, „city“:“paprola“, „state“:“HP“, „zip“:“176115″, „location“:[31.8955385, 76.8380405], „fees“:2000, „tags“:[„Senior
Secondary“, „beautiful campus“], „rating“:“3.5\n„}
{ „index“:{ „_index“:“schools“, „_type“:“school“, „_id“:“2″ }}
{ „name“:“Saint Paul School“, „description“:“ICSE Afiliation“, „street“:“Dawarka“, „city“:“Delhi“, „state“:“Delhi“, „zip“:“110075″,“location“:[28.5733056, 77.0122136], „fees“:5000,“tags“:[„Good F
aculty“, „Great Sports“], „rating“:“4.5\n“ }
{ „index“:{„_index“:“schools“, „_type“:“school“, „_id“:“3″}}
{ „name“:“Crescent School“, „description“:“State Board Affiliation“, „street“:“Tonk Road“, „city“:“Jaipur“, „state“:“RJ“, „zip“:“176114″,“location“:[26.8535922, 75.7923988],“fees“:2500, „tags“:[„
Well equipped labs“], „rating“:“4.5\n„}
Important: the final line of data must end with a newline character \n. Each newline character may be preceded by a carriage return \r. Otherwise, you will get an error:
{
„error“ : {
„root_cause“ : [
{
„type“ : „illegal_argument_exception“,
„reason“ : „The bulk request must be terminated by a newline [\n]“
}
],
„type“ : „illegal_argument_exception“,
„reason“ : „The bulk request must be terminated by a newline [\n]“
},
„status“ : 400
}
root@pve-02-ubuntu-2:~# curl -XPUT „localhost:9200/test/_bulk?pretty“ -H ‚Content-Type: application/json‘ –data-binary @test.json
{
„took“ : 12,
„errors“ : false,
„items“ : [
{
„index“ : {
„_index“ : „schools“,
„_type“ : „school“,
„_id“ : „1“,
„_version“ : 2,
„result“ : „updated“,
„_shards“ : {
„total“ : 2,
„successful“ : 1,
„failed“ : 0
},
„_seq_no“ : 3,
„_primary_term“ : 1,
„status“ : 200
}
},
{
„index“ : {
„_index“ : „schools“,
„_type“ : „school“,
„_id“ : „2“,
„_version“ : 2,
„result“ : „updated“,
„_shards“ : {
„total“ : 2,
„successful“ : 1,
„failed“ : 0
},
„_seq_no“ : 4,
„_primary_term“ : 1,
„status“ : 200
}
},
{
„index“ : {
„_index“ : „schools“,
„_type“ : „school“,
„_id“ : „3“,
„_version“ : 2,
„result“ : „updated“,
„_shards“ : {
„total“ : 2,
„successful“ : 1,
„failed“ : 0
},
„_seq_no“ : 5,
„_primary_term“ : 1,
„status“ : 200
}
}
]
}
root@pve-02-ubuntu-2:~# curl -X GET „localhost:9200/_cat/indices?v&pretty“
health status index uuid pri rep docs.count docs.deleted store.size pri.store.size
yellow open schools iQOagup7Qv2mcCtN5CDScA 1 1 3 0 9.9kb 9.9kb
yellow open shakespeare rV1bXB_8RGeIdd-zKSX0SQ 1 1 111396 0 19.3mb 19.3mb
yellow open products o5Xg9jLxQh-ZgXbzWQpa0A 1 1 2 0 8.5kb 8.5kb

Leave a Reply

You must be logged in to post a comment.