Answer the question
In order to leave comments, you need to log in
How to search in elasticsearch by prefix?
I decided to study elasticsearch, and I immediately come across questions (before that, I only used Sphinx).
There is a certain index test , there is a type country , it contains documents with country names and their descriptions.
I make the first request:
curl -XGET 'http://localhost:9200/test/country/_search?pretty=true' -d '
{
"query": {
"match": {
"country": "Украина"
}
}
}'
{
"took" : 33,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"failed" : 0
},
"hits" : {
"total" : 1,
"max_score" : 0.24701709,
"hits" : [ {
"_index" : "test",
"_type" : "country",
"_id" : "AU-xLqS2KzVZz9Yq1Hgw",
"_score" : 0.24701709,
"_source":{"langId":1,"langUrl":"ru","langActive":1,"countryId":2,"countryUrl":"ukraine","countryActive":1,"country":"Украина"}
curl -XGET 'http://localhost:9200/test/country/_search?pretty=true' -d '
{
"query": {
"prefix": {
"country": "Украи"
}
}
}'
{
"took" : 5,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"failed" : 0
},
"hits" : {
"total" : 0,
"max_score" : null,
"hits" : [ ]
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question