[英]why elasticsearch keyword search not working?
我使用 NLog 將日志消息寫入 Elasticsearch,索引結構在這里:
"mappings": {
"logevent": {
"properties": {
"@timestamp": {
"type": "date"
},
"MachineName": {
"type": "text",
"fields": {
"keyword": {
"ignore_above": 256,
"type": "keyword"
}
}
},
"level": {
"type": "text",
"fields": {
"keyword": {
"ignore_above": 256,
"type": "keyword"
}
}
},
"message": {
"type": "text",
"fields": {
"keyword": {
"ignore_above": 256,
"type": "keyword"
}
}
}
}
}
}
我能夠使用文本搜索獲得結果:
GET /webapi-2022.07.28/_search
{
"query": {
"match": {
"message": "ERROR"
}
}
}
結果“命中”:[{“_index”:“webapi-2022.07.28”,“_type”:“logevent”,“_id”:“IFhYQoIBRhF4cR9wr-ja”,“_score”:4.931916,“_source”:{“@時間戳”:“2022-07-28T01:07:58.8822339Z”,“級別”:“錯誤”,“消息”:“”“2022-07-28 09:07:58.8822|錯誤|AppSrv.Filter.AccountAuthorizeAttribute| [KO17111808]-[172.10.2.200]-[ERROR]-"message"""", "MachineName": "WIN-EPISTFOBD41" } } //..... ]
但是當我使用關鍵字時,我什么也得不到:
GET /webapi-2022.07.28/_search
{
"query": {
"term": {
"message.keyword": "ERROR"
}
}
}
我嘗試了術語和匹配,結果是一樣的。
這是因為消息字段不僅包含ERROR
,而且在.keyword
字段中還有其他字符串,您需要僅在您的情況下使用text
搜索,您只能在精確搜索的情況下使用.keyword
字段。
如果您的message
字段僅包含ERROR
字符串,而不是僅在.keyword
上搜索會產生結果,您可以通過索引示例文檔來自己測試它。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.