2016-09-07 57 views
0

我试图编写一个Elasticsearch查询,它将返回具有嵌套字段的元素。不过,我显然遇到了很多困难。我给这家字段映射通常看起来如下:筛选存在嵌套字段的Elaticsearch查询

{ "myType": { "properties": { "hello": { "type": "nested", "properties": { "foo": {"type": "string", "index": "not_analyzed"}, "bar": {"type": "string", "index": "not_analyzed"}, } } } } }

我的查询一般如下: { "query": { "filtered": { "filter": { "exists": { "field": "hello.foo" } } } } }

该查询返回0匹配的文件,即使我知道有匹配的文件。

我也尝试在nested查询中使用exists查询,但给出了有关nested查询不支持exists查询的错误消息。

我对Elasticsearch 2.3进行测试任何帮助将不胜感激!

回答

1

我希望这将有助于

{ 
    "query": { 
    "bool": { 
     "must": [ 
     { 
      "nested": { 
      "path": "hello", 
      "filter": { 
       "term": {  // replace term to "match" in case of fulltext 
       "hello.foo": "value to be searched" 
       } 
      } 
      } 
     } 
     ] 
    } 
    }, 
    "from": 0, 
    "size": 50 
} 
+0

哈哈,我正要后,我会找到我的答案从旧的博客文章(http://joelabrahamsson.com/elasticsearch-nested-mapping-和过滤器/)。但是这正是它所说的(在嵌套过滤器中使用另一个过滤器,然后使用exists过滤器)。我将编辑你的'term'过滤器作为'存在'过滤器并且标记你的答案是正确的!谢谢您的帮助! – user114241