Elasticsearch 过滤器查询没有 return 任何文档
Elasticsearch filter query does not return any document
我不明白为什么如果我用这样的过滤器查询 Elasticsearch:
curl -H'content-type: application/json' "localhost:9200/.kibana/_search" -d '{
"query": {
"bool": {
"filter": [
{
"term": {
"type": "index-pattern"
}
}
]
}
}
}'
{"took":0,"timed_out":false,"_shards":{"total":4,"successful":4,"skipped":0,"failed":0},"hits":{"total":{"value":0,"relation":"eq"},"max_score":null,"hits":[]}}
如您所见,我的结果集是空的。
但是我确实有一个文档,其中“type”字段等于“index-pattern”。
{
"_index": ".kibana",
"_type": "_doc",
"_id": "index-pattern:c37de740-7e94-11eb-b6c2-4302716621be",
"_score": 0,
"_source": {
"index-pattern": {
"title": "r*",
"timeFieldName": "@timestamp",
"fields": "<omitted - too long>"
},
"type": "index-pattern",
"references": [],
"migrationVersion": {
"index-pattern": "7.6.0"
},
"updated_at": "2021-03-06T15:58:18.062Z"
}
}
我的查询有什么问题?
当 type
字段默认映射为 text
并且您想对其应用 term
查询时,连字符将阻止查询匹配,因为 text
由 the standard analyzer which removes hyphens and other special characters upon ingest. Having said that, the term
query returns 文档分析,这些文档包含 精确 匹配(包括特殊字符),这导致您的原始查询不 return任何东西。
所以改为 .keyword
multi-field:
curl -H'content-type: application/json' "localhost:9200/.kibana/_search" -d '{
"query": {
"bool": {
"filter": [
{
"term.keyword": {
"type": "index-pattern"
}
}
]
}
}
}'
我不明白为什么如果我用这样的过滤器查询 Elasticsearch:
curl -H'content-type: application/json' "localhost:9200/.kibana/_search" -d '{
"query": {
"bool": {
"filter": [
{
"term": {
"type": "index-pattern"
}
}
]
}
}
}'
{"took":0,"timed_out":false,"_shards":{"total":4,"successful":4,"skipped":0,"failed":0},"hits":{"total":{"value":0,"relation":"eq"},"max_score":null,"hits":[]}}
如您所见,我的结果集是空的。 但是我确实有一个文档,其中“type”字段等于“index-pattern”。
{
"_index": ".kibana",
"_type": "_doc",
"_id": "index-pattern:c37de740-7e94-11eb-b6c2-4302716621be",
"_score": 0,
"_source": {
"index-pattern": {
"title": "r*",
"timeFieldName": "@timestamp",
"fields": "<omitted - too long>"
},
"type": "index-pattern",
"references": [],
"migrationVersion": {
"index-pattern": "7.6.0"
},
"updated_at": "2021-03-06T15:58:18.062Z"
}
}
我的查询有什么问题?
当 type
字段默认映射为 text
并且您想对其应用 term
查询时,连字符将阻止查询匹配,因为 text
由 the standard analyzer which removes hyphens and other special characters upon ingest. Having said that, the term
query returns 文档分析,这些文档包含 精确 匹配(包括特殊字符),这导致您的原始查询不 return任何东西。
所以改为 .keyword
multi-field:
curl -H'content-type: application/json' "localhost:9200/.kibana/_search" -d '{
"query": {
"bool": {
"filter": [
{
"term.keyword": {
"type": "index-pattern"
}
}
]
}
}
}'