Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/305.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 查询返回两个文档,而不是一个_C#_.net_<img Src="//i.stack.imgur.com/RUiNP.png" Height="16" Width="18" Alt="" Class="sponsor Tag Img">elasticsearch_Nest - Fatal编程技术网 elasticsearch,nest,C#,.net,elasticsearch,Nest" /> elasticsearch,nest,C#,.net,elasticsearch,Nest" />

C# 查询返回两个文档,而不是一个

C# 查询返回两个文档,而不是一个,c#,.net,elasticsearch,nest,C#,.net,elasticsearch,Nest,我还尝试进行JSON查询,但得到0次点击: { "reviewer-test-index": { "aliases": {}, "mappings": { "historyRecord": { "properties": { "groupName": { "type": "string" }, "gr

我还尝试进行JSON查询,但得到0次点击:

{
   "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}}
            ]
         }
    }
  }
  }
}