C# 查询返回两个文档,而不是一个
我还尝试进行JSON查询,但得到0次点击:C# 查询返回两个文档,而不是一个,c#,.net,elasticsearch,nest,C#,.net,elasticsearch,Nest,我还尝试进行JSON查询,但得到0次点击: { "reviewer-test-index": { "aliases": {}, "mappings": { "historyRecord": { "properties": { "groupName": { "type": "string" }, "gr
{
"reviewer-test-index": {
"aliases": {},
"mappings": {
"historyRecord": {
"properties": {
"groupName": {
"type": "string"
},
"groupNo": {
"type": "integer"
},
"instrType": {
"type": "integer"
},
"instrumentAddress": {
"type": "string"
},
"insturmentName": {
"type": "string"
},
"macAddr": {
"type": "string"
},
"uhhVersion": {
"type": "string"
}
}
},
"settings": {
"index": {
"creation_date": "1434557536720",
"number_of_shards": "1",
"number_of_replicas": "0",
"version": {
"created": "1050299"
},
"uuid": "FfQADLGVQVOPV3913exKsw"
}
},
"warmers": {}
}
}
term
过滤器不分析要搜索的文本。也就是说,如果搜索000A8D810F5A
,这正是要搜索的内容(包括大写字母)
但是,您的macAddr
和instrumentname
字段和其他字段只是string
s。也就是说,他们使用标准的分析工具,将术语小写。因此,您正在搜索000A8D810F5A
,但在索引中可能有000A8D810F5A
(注意小写字母)
因此,您需要让这些字段未分析
或使用关键字
分析器进行分析,或者,如果您希望在默认情况下使用标准
分析器对其进行分析,请添加一个未分析
或关键字
的原始
多字段,并在搜索中使用该字段。例如,“term”:{“macAddr.raw”:“000A8D810F5A”}
建议的映射:
GET _search
{
"query" :{
"filtered": {
"query": {
"match_all": { }
},
"filter": {
"bool" : {
"must" : [
{"term" : { "macAddr" : "000A8D810F5A" } },
{"term" : { "insturmentName" : "Amin's furnace" } },
{"term" : { "instrumentAddress" : "8D810F5A"}},
{"term" : { "uhhVersion" : "v2.5"}},
{"term" : { "groupName" : "Amin's Group"}},
{"term" : { "groupNo" : 2}},
{"term" : { "instrType" : 60}}
]
}
}
}
}
}
Response:
{
"took": 3,
"timed_out": false,
"_shards": {
"total": 4,
"successful": 3,
"failed": 0
},
"hits": {
"total": 0,
"max_score": null,
"hits": []
}
}
建议查询:
"mappings": {
"historyRecord": {
"properties": {
"groupName": {
"type": "string",
"fields": {
"raw": {
"type": "string",
"index": "not_analyzed"
}
}
},
"groupNo": {
"type": "integer"
},
"instrType": {
"type": "integer"
},
"instrumentAddress": {
"type": "string",
"fields": {
"raw": {
"type": "string",
"index": "not_analyzed"
}
}
},
"insturmentName": {
"type": "string",
"fields": {
"raw": {
"type": "string",
"index": "not_analyzed"
}
}
},
"macAddr": {
"type": "string",
"fields": {
"raw": {
"type": "string",
"index": "not_analyzed"
}
}
},
"uhhVersion": {
"type": "string",
"fields": {
"raw": {
"type": "string",
"index": "not_analyzed"
}
}
}
}
}
然后你的分析仪有点可疑。你能为该索引和两个有问题的文档提供映射吗?在映射中,我得到了所有字段的analyze=true和store=false,你能分享那些你认为应该匹配的字段的实际文档值吗?@andrestefan我用映射和查询示例更新了帖子
"mappings": {
"historyRecord": {
"properties": {
"groupName": {
"type": "string",
"fields": {
"raw": {
"type": "string",
"index": "not_analyzed"
}
}
},
"groupNo": {
"type": "integer"
},
"instrType": {
"type": "integer"
},
"instrumentAddress": {
"type": "string",
"fields": {
"raw": {
"type": "string",
"index": "not_analyzed"
}
}
},
"insturmentName": {
"type": "string",
"fields": {
"raw": {
"type": "string",
"index": "not_analyzed"
}
}
},
"macAddr": {
"type": "string",
"fields": {
"raw": {
"type": "string",
"index": "not_analyzed"
}
}
},
"uhhVersion": {
"type": "string",
"fields": {
"raw": {
"type": "string",
"index": "not_analyzed"
}
}
}
}
}
{
"query" :{
"filtered": {
"query": {
"match_all": { }
},
"filter": {
"bool" : {
"must" : [
{"term" : { "macAddr.raw" : "000A8D810F5A" } },
{"term" : { "insturmentName.raw" : "Amin's furnace" } },
{"term" : { "instrumentAddress.raw" : "8D810F5A"}},
{"term" : { "uhhVersion.raw" : "v2.5"}},
{"term" : { "groupName.raw" : "Amin's Group"}},
{"term" : { "groupNo" : 2}},
{"term" : { "instrType" : 60}}
]
}
}
}
}
}