我对ElasticSearch中的 query_string
查询有疑问 . 我想在索引中的所有类型和字段上创建全文搜索 . query_string
字符串是否针对嵌套对象执行?例如,我有这个映射
{
"my_index": {
"mappings": {
"my_type": {
"properties": {
"group": {
"type": "string"
},
"user": {
"type": "nested",
"properties": {
"first": {
"type": "string"
},
"last": {
"type": "string"
}
}
}
}
}
}
}
}
和查询
GET /my_index/_search
{
"query": {
"query_string" : {
"query" : "paul"
}
}
}
因此,当我调用查询时,ES将搜索所有字段,包括嵌套或仅在my_type对象中,对于嵌套搜索,我将不得不使用嵌套查询?
2 回答
您不能从根的query_string引用嵌套字段 . 即这不起作用:
要在特定的嵌套字段中搜索,必须使用嵌套子句:
但是,我发现伪字段“_all”确实包含嵌套字段,因此该查询将在myNestedObj.myTextField(以及其他任何地方)中找到包含“food”的文档
尝试: