2017-06-22 62 views
0

我在lastName字段中按照某种方式出现必须具有“Thomas”的文档来查询我的索引,并且还应根据geo_point查询返回返回结果。 geo_point查询出现在should子句中,因为可能有多个传入。如果有任何匹配,我希望文档以命中形式返回。任何想法为什么这不起作用?我遵循文档as outlined here为什么不是使用组合查询的Elasticsearch查询返回预期结果?

“应:至少其中一个查询必须匹配等效的OR。”

{ 
"sort": [{ 
    "_score": { 
     "order": "desc" 
    } 
}], 
"query": { 
    "bool": { 
     "must": [{ 
      "query_string": { 
       "default_field": "lastName", 
       "query": "Thomas" 
      } 
     }], 
     "should": [{ 
      "geo_distance": { 
       "distance": "5mi", 
       "coordinates": "32.798913, -79.998085" 
      } 
     }] 
    } 
} 

}

+0

你肯定你的'coordinates'字段类型'geo_point'? – Val

+0

是的,的映射是正确的 – sean

+0

你确定'坐标'首先是指定纬度,然后是经度而不是其他的方式吗? – Val

回答

0

嵌套是很重要的。在上面的代码中,shouldmust并排;因此,其功能类似于“查找姓氏像托马斯或任何在查尔斯顿内生活的5米的人”。下面将geo_point查询与任何其他must子句嵌套在一起。

“寻找像托马斯(5MI查尔斯顿OR 5MI内抵达亚特兰大OR等姓氏。”

{ 
    "sort": [{ 
     "_score": { 
      "order": "desc" 
     } 
    }], 
    "query": { 
     "bool": { 
      "must": [{ 
        "query_string": { 
         "default_field": "lastName", 
         "query": "Thomas" 
        } 
       }, 
       { 
        "bool": { 
         "should": [{ 
          "geo_distance": { 
           "distance": "5mi", 
           "coordinates": "32.798913, -79.998085" 
          } 
         }] 
        } 
       } 
      ] 
     } 
    } 
}