小编典典

无论字段的位置如何,都在嵌套文档中搜索字段

elasticsearch

考虑一下这样的Elasticsearch中的文档:

{
  "id": 1,
  "Comment": "Comment text",
  "Reply": [{
    "id": 2,
    "Comment": "Nested comment text",
  }, {
    "id": 3,
    "Comment": "Another nested comment text",
  }]
}

我想搜索时id == 2不知道它是在文档的第一层还是第二层。这可能吗?还请记住,嵌套级别可以是任何东西(在开发时未知)。

如果可能的话,在id == 2不知道id文档第二级中存在的情况下通过搜索返回该文档的查询是什么?


阅读 349

收藏
2020-06-22

共1个答案

小编典典

试试这个:

{
  "query": {
    "query_string": {
      "fields": ["*.id","id"],
      "query": "2"
    }
  }
}
2020-06-22