2016-08-16 55 views
1

考虑这样的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而返回此文档的查询是什么?

+1

你知道,在ES'nested'有着特殊的意义。那么这个领域真的是[嵌套](https://www.elastic.co/guide/en/elasticsearch/reference/2.0/nested.html)领域? –

+0

我不好,你说得对。我错过了这个例子。我会更新干。谢谢。但问题依然如此。 – Mehran

回答

2

试试这个:

{ 
    "query": { 
    "query_string": { 
     "fields": ["*.id","id"], 
     "query": "2" 
    } 
    } 
} 
+0

谢谢。是否有可能将'query_string'与其他类型的查询混合使用,比如'term'和'must'? – Mehran

+1

是的,使用'bool'并将'query_string'放在任何你认为合适的地方:'should','must'等等。这取决于你已经有了什么查询。 –

+0

然后,如果我不能自己弄清楚,我会发布另一个问题,因为现在我在这方面遇到困难!再次感谢。 – Mehran