基本 elasticsearch "terms" 查询的问题
Issue with a basic elasticsearch "terms" query
我正在尝试 运行 一个简单的 elasticsearch 术语查询,如下所示(使用意义 chrome 扩展):
GET _search
{
"query": {
"terms": {
"childcareTypes": [
"SHARED_CHARGE",
"OUT_OF_SCHOOL"
],
"minimum_match": 2
}
}
}
这个returns 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"
}
}
}
}
谁能解释一下 为什么我的条款查询 returns 0 次点击?
and my mapping does show that the field childcareTypes is analyzed:
这正是您的问题所在:该字段已被分析,但是,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
系列中的查询。
之所以会这样,是因为terms
不会分析输入。这意味着它将精确搜索 SHARED_CHARGE
和 OUT_OF_SCHOOL
(大写字母)。而您将该字段设置为 "index": "analyzed"
,这意味着 ES 将使用 standard
分析器来索引数据。
对于 SHARED_CHARGE
ES 存储 shared_charge
。
对于 OUT_OF_SCHOOL
ES 商店 out_of_school
.
我正在尝试 运行 一个简单的 elasticsearch 术语查询,如下所示(使用意义 chrome 扩展):
GET _search
{
"query": {
"terms": {
"childcareTypes": [
"SHARED_CHARGE",
"OUT_OF_SCHOOL"
],
"minimum_match": 2
}
}
}
这个returns 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"
}
}
}
}
谁能解释一下 为什么我的条款查询 returns 0 次点击?
and my mapping does show that the field childcareTypes is analyzed:
这正是您的问题所在:该字段已被分析,但是,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
系列中的查询。
之所以会这样,是因为terms
不会分析输入。这意味着它将精确搜索 SHARED_CHARGE
和 OUT_OF_SCHOOL
(大写字母)。而您将该字段设置为 "index": "analyzed"
,这意味着 ES 将使用 standard
分析器来索引数据。
对于 SHARED_CHARGE
ES 存储 shared_charge
。
对于 OUT_OF_SCHOOL
ES 商店 out_of_school
.