如何告诉Elasticsearch返回搜索结果的搜索参数?

时间:2018-06-15 09:40:06

标签: elasticsearch

我正在建立多搜索请求,以便找到与其他类似的位置(但有100个子搜索):

{}
{"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"}}]}

返回如下结果:

{
  "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
     }
  ]
}

我读到结果顺序与请求顺序匹配,但是是否可以告诉Elasticsearch将请求参数放入结果中?我想得到用于匹配我的距离滤波器的段的两个末端位置......

1 个答案:

答案 0 :(得分:1)

您可以使用命名搜索:https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-named-queries-and-filters.html

通过添加:"_name" : "search_1",该名称将在返回的匹配文档中。