我正在尝试运行一个简单的弹性搜索术语查询,如下所示(使用sense chrome扩展名):
GET _search
{
"query": {
"terms": {
"childcareTypes": [
"SHARED_CHARGE",
"OUT_OF_SCHOOL"
],
"minimum_match": 2
}
}
}
这会返回0次点击:
{
"took": 2,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 0,
"max_score": null,
"hits": []
}
}
我不确定为什么因为match_all查询确实显示三条记录中的两条匹配:
GET _search
{
"query": {
"match_all": {}
}
}
的产率:
{
"took": 3,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 3,
"max_score": 1,
"hits": [
{
"_index": "bignibou",
"_type": "advertisement",
"_id": "1",
"_score": 1,
"_source": {
"id": 1,
"childcareWorkerType": "AUXILIAIRE_PARENTALE",
"childcareTypes": [
"SHARED_CHARGE",
"OUT_OF_SCHOOL"
],
"giveBath": "YES"
}
},
{
"_index": "bignibou",
"_type": "advertisement",
"_id": "2",
"_score": 1,
"_source": {
"id": 2,
"childcareWorkerType": "AUXILIAIRE_PARENTALE",
"childcareTypes": [
"SHARED_CHARGE",
"OUT_OF_SCHOOL"
],
"giveBath": "EMPTY"
}
},
{
"_index": "bignibou",
"_type": "advertisement",
"_id": "3",
"_score": 1,
"_source": {
"id": 3,
"childcareWorkerType": "AUXILIAIRE_PARENTALE",
"childcareTypes": [
"SHARED_CHARGE"
],
"giveBath": "YES"
}
}
]
}
}
我的映射确实显示了字段childcareTypes被分析:
{
"advertisement": {
"dynamic": "false",
"properties": {
"id": {
"type": "long",
"store": "yes"
},
"childcareWorkerType": {
"type": "string",
"store": "yes",
"index": "analyzed"
},
"childcareTypes": {
"type": "string",
"store": "yes",
"index": "analyzed"
},
"giveBath": {
"type": "string",
"store": "yes",
"index": "analyzed"
}
}
}
}
有人可以解释为什么我的条款查询会返回0次点击?
答案 0 :(得分:3)
就是这样,因为terms
不会分析输入。这意味着它将完全搜索SHARED_CHARGE
和OUT_OF_SCHOOL
(大写字母)。而您将该字段设为"index": "analyzed"
,这意味着ES将使用standard
分析器对数据编制索引。
对于SHARED_CHARGE
ES商店shared_charge
。
对于OUT_OF_SCHOOL
ES商店out_of_school
。
答案 1 :(得分:2)
我的映射确实显示了字段childcareTypes被分析:
这正是您的问题所在:分析字段,但terms
查询直接查找未分析的字词(请参阅here)。
更准确地说,索引值如下所示:
shared_charge
out_of_school
您的terms
查询搜索:
SHARED_CHARGE
OUT_OF_SCHOOL
您可以像尝试此查询一样检查此行为......
POST /bignibou/_search
{
"query": {
"terms": {
"childcareTypes": [
"shared_charge",
"out_of_school"
]
}
}
}
...你会找到你的文档。
您应该在字段的not_analyzed
版本或match
系列的查询中使用您之前的查询。