elasticsearch - Elasticsearch 必须在列表对象上
问题描述
我正在使用 Elastic 6.0。我的 kibana 查询如下
"bool": {
"must": [
{
"match": {
"relationships.relation": {
"query": "spouse"
}
}
},
{
"match": {
"relationships.first_name": {
"query": "james"
}
}
},
{
"match": {
"relationships.last_name": {
"query": "smith"
}
}
}
]
}
这给了我结果
1. "relationships": [
{
"first_name": "John",
"last_name": "Heafner",
"relation": "Father"
},
{
"first_name": "Mary",
"last_name": "Dellinger",
"relation": "Mother"
},
{
"first_name": "James S.",
"last_name": "Smith",
"relation": "Spouse"
}
]
2. "relationships": [
{
"first_name": "James",
"last_name": "Hickey",
"relation": "Father"
},
{
"first_name": "Mary",
"last_name": "Raftery",
"relation": "Mother"
},
{
"first_name": "Richard",
"last_name": "Smith",
"relation": "Spouse"
}
]
我只想要第一个结果,因为它包含基于我的查询的完全匹配
{ "first_name": "James S.", "last_name": "Smith", "relation": "Spouse" } 我已经尝试过术语查询,但它给出了结果与上述相同。任何建议都会有很大帮助。
解决方案
这听起来像您已relationships
映射为object
type。为此,relationships
需要将其映射为一种nested
类型,并且您应该使用nested
查询来查询嵌套对象的字段。