我将一些任意数据扔进elasticsearch(日志)。写入进行得很好,大多数查询都能正常工作,但是我有一个“reqId”字段,该字段永不匹配。
$ curl localhost:9200/log_general/log/c9811a1a-6710-424a-b67d-d02d6ad75c89 | jq .
{
"_index": "log_general",
"_type": "log",
"_id": "c9811a1a-6710-424a-b67d-d02d6ad75c89",
"_version": 1,
"found": true,
"_source": {
"body": {
"body": {
"media": [],
"parentId": "5a695c7bda3c26391649e332",
"text": "Super bulk comment 25"
},
"method": "post",
"url": "/addComment",
"xuserid": "5a695c30da3c26391649e17f"
},
"logType": "request_start",
"reqId": "5T42Q1AUmd9LS1E8Q",
"reqUrl": "/addComment"
}
}
我可以尝试通过 reqId 搜索
curl -XPOST localhost:9200/_search -H 'content-type: application/json' --data-binary @sample-query
样本查询:
{
"query": {
"bool": {
"must": [
{
"term": {
"reqId": "5T42Q1AUmd9LS1E8Q"
}
}
],
"filter": [],
"should": []
}
}
}
没有命中,也没有错误。
如果我尝试其他字段,它将返回结果。其中两个结果具有相同的reqId。
{
"query": {
"bool": {
"must": [
{
"term": {
"logType": "request_start"
}
}
],
"filter": [],
"should": []
}
}
}
这是为两个字段生成的映射elasticsearch
"logType": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"reqId": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
真的不知道问题可能在这里。
最佳答案
在 flex 搜索6中,为每个字符串字段生成两种类型的映射。
一个是文本,另一个是关键字。
所以发生的是被索引的 token 是 5t42q1aumd9ls1e8q ,您正在搜索5T42Q1AUmd9LS1E8Q
可以有两种解决方案
关于elasticsearch - 简单查询与一个特定字段不匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48474710/