如何过滤嵌套数组?

eva*_*van 5 arrays nested filter elasticsearch

我在ES中使用嵌套文档.我在一个实体中嵌套了数组,我希望能够使用嵌套查询过滤数组(不仅仅是过滤器根/父文档,还有嵌套数组).

嵌套过滤器可以过滤根文档.例如,如果我有索引'blogs'并输入'blog'并且在博客文档中我有属性'comments'(注释数组),在映射中有{"type":"nested"},那么例如我想要过滤博客的评论标题为'今天'(例如匹配查询),但在每个博客中我也只想显示标题中包含'今天'的评论.

我知道如何嵌套过滤器.父子关系也不利于此目的,因为作为父文档的一部分,没有子文档作为响应.

有没有办法直接在elasticsearch中执行此操作,而无需向应用程序添加额外的逻辑,这可能会影响性能?或者是否有计划在下一版本或类似的东西中将其添加为嵌套查询/过滤器中的新选项?

谢谢

...加

例如,看看这个doc:

 .....
"blogs" :[
    {
         "id":1000,
         "content":"hello world!!!",
         "author:"evan",
         "createTime":"2013-05-31",
          "comments" : [
                   {"author":"jack", id:"1", "content":"test test","createTime":"2013-05-31"},
                   {"author":"tom",  id:"2", "content":"test test","createTime":"2013-05-30"},
                   {"author":"oliver", id:"3", "content":"test test","createTime":"2013-05-30"},
                   {"author":"Jonesie", id:"4", "content":"test test","createTime":"2013-05-29"}
           ]
    },
    {
         "id":1001,
         "content":"test data",
         "author:"jack",
         "createTime":"2013-05-30",
          "comments" : [
                   {"author":"Zach", id:"11", "content":"test data 1","createTime":"2013-05-31"},
                   {"author":"tom",  id:"21", "content":"test data 2","createTime":"2013-05-31"},
                   {"author":"oliver", id:"31", "content":"test test 3","createTime":"2013-05-28"},
                   {"author":"Jonesie", id:"41", "content":"test test 4","createTime":"2013-05-27"}
           ]
    }
]
.....

我想运行查询,如:

按blogs.createTime =='2013-05-31'过滤并​​过滤blogs.comments.createTime =='2013-05-31'

期待:

 .....
"blogs" :[
    {
         "id":1000
         "content":"hello world!!!",
         "author::"evan",
         "createTime":"2013-05-31"
          "comments" : [
                   {"author":"jack", id:"1", "content":"test test","createTime":"2013-05-31"}
           ]
    } 
]
....

谢谢

Gee*_*Jan 1

简而言之:你不能。您需要在自己的代码中过滤嵌套文档。

这是一个已知问题:

“将匹配的嵌套文档公开给查询并排序” https://github.com/elasticsearch/elasticsearch/issues/1383

“每次点击返回匹配的嵌套内部对象。”

https://github.com/elasticsearch/elasticsearch/issues/3022