Reputation: 5957
I'm building multi-search request in order to find locations close to other like (but with 100 sub-search):
{}
{"query":{"filtered":{"filter":{"geo_distance":{"distance":"10m","location":{"lat":48.8643,"lon":2.3774}}}}},"size":1,"sort":[{"_geo_distance":{"location":{"lat":48.8643,"lon":2.3774},"order":"asc","unit":"m","mode":"min","distance_type":"plane"}}]}
{}
{"query":{"filtered":{"filter":{"geo_distance":{"distance":"10m","location":{"lat":49.4293,"lon":3.3734}}}}},"size":1,"sort":[{"_geo_distance":{"location":{"lat":49.4293,"lon":3.3734},"order":"asc","unit":"m","mode":"min","distance_type":"plane"}}]}
It returns results like:
{
"responses" : [
{
"took" : 30,
"timed_out" : false,
"hits" : {
"hits" : [
{
"sort" : [
2.48215343865
],
"_index" : "index1",
"_id" : "255610",
"_type" : "my_type",
"_source" : {
"rep" : null,
"location" : {
"lat" : 48.8645413506779,
"lon" : 2.37757252267366
},
"name" : "Fastfood 3"
},
"_score" : null
}
],
"max_score" : null,
"total" : 45
},
"_shards" : {
"total" : 4,
"failed" : 0,
"successful" : 4
}
},
{
"_shards" : {
"failed" : 0,
"successful" : 4,
"total" : 4
},
"hits" : {
"hits" : [
{
"sort" : [
89.301169725
],
"_id" : "6505",
"_index" : "index1",
"_type" : "my_type",
"_source" : {
"numero" : 1,
"location" : {
"lat" : 49.8603911006058,
"lon" : 3.37063212374192
},
"name" : "Resto 1"
},
"_score" : null
}
],
"max_score" : null,
"total" : 2117987
},
"timed_out" : false,
"took" : 120
}
]
}
I read that results order matches request order, but is it possible to tell Elasticsearch to put requests parameters into the result? I would like to get both extremities location of the segment used to match my distance filter...
Upvotes: 0
Views: 50
Reputation: 22691
You can use named search: https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-named-queries-and-filters.html
By adding: "_name" : "search_1"
the name will be in returned hit documents.
Upvotes: 1