2016-06-28 204 views
1

我有三个以下参数,我将通过运行查询,它们是;弹性搜索我如何查询多个匹配或功能

  • 查询 - 无论是地方名称,描述或空,
  • LAT - 一个地方或空的任纬度,
  • LON - 任的经度放置或空

基于上述参数,我根据query得分查询items列表,然后计算resultlat, lon之间的距离。

现在,我有以下脚本来获得基于querydistanceitems;

{ 
    "query": { 
     "function_score": { 
      "query": { 
       "bool": { 
        "must": [{ 
         "multi_match" : { 
          "query": "Lippo", 
          "fields": [ "name^6", "city^5", "country^4", "position^3", "address_line^2", "description"] 
         } 
        }] 
       } 
      }, 
      "functions": [ 
       { 
        "gauss": { 
         "position": { 
          "origin": "-6.184652, 106.7518749", 
          "offset": "2km", 
          "scale": "10km", 
          "decay": 0.33 
         } 
        } 
       } 
      ] 
     } 
    } 
} 

但事实是,如果query是空的,不会有结果的。我想要的是,结果是基于querydistance

无论如何要实现这一目标吗?任何建议表示赞赏。

回答

2

zero_terms_query选项的多重匹配设置为all应该允许您在查询为空时获得结果。

例子:

{ 
    "query": { 
     "function_score": { 
      "query": { 
       "bool": { 
        "must": [{ 
         "multi_match" : { 
          "query": "Lippo", 
          "fields": [ "name^6", "city^5", "country^4", "position^3", "address_line^2", "description"], 
          "zero_terms_query" : "all" 
         } 
        }] 
       } 
      }, 
      "functions": [ 
       { 
        "gauss": { 
         "position": { 
          "origin": "-6.184652, 106.7518749", 
          "offset": "2km", 
          "scale": "10km", 
          "decay": 0.33 
         } 
        } 
       } 
      ] 
     } 
    } 
} 
+0

这样做对我来说..但是,我终于打消了我的'functions'检查距离。我最终使用了简单的'query'和'filter'。谢谢 – choz

+0

你也可以发布^^这个版本。 – kaulmonish