为什么NEST ElasticClient找不到文档?

时间:2018-07-15 00:03:06

标签: c# elasticsearch nest elasticsearch.net

当我使用Kibana对Elasticsearch执行以下Searchrequest

GET _search
{
  "query": {
    "query_string": {
      "query": "PDB_W2237.docx", 
      "default_operator": "AND"
    }
  }
}

它返回:

{
  "took": 14,
  "timed_out": false,
  "_shards": {
    "total": 15,
    "successful": 15,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": 1,
    "max_score": 6.3527603,
    "hits": [
      {
        "_index": "proconact",
        "_type": "proconact",
        "_id": "68cecf2c-7e5a-11e5-80fa-000c29bd9450",
        "_score": 6.3527603,
        "_source": {
          "Id": "68cecf2c-7e5a-11e5-80fa-000c29bd9450",
          "ActivityId": "1bad9115-7e5a-11e5-80fa-000c29bd9450",
          "ProjectId": "08938a1d-2429-11e5-80f9-000c29bd9450",
          "Filename": "PDB_W2237.docx"
        }
      }
    ]
  }
}

当我像使用NEST ElasticClient时

var client = new ElasticClient();
var searchResponse = client.Search<Hit>(new SearchRequest {          
    Query = new QueryStringQuery {
         Query = "DB_W2237.docx",
         DefaultOperator = Operator.And
    }
});

它确实返回0次点击。

以下是匹配中4个字段的索引映射:

{
  "proconact": {
    "mappings": {
      "proconact": {
        "properties": {
          "ActivityId": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          },
          "Filename": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          },
          "Id": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          },
          "ProjectId": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          }
        }
      }
    }
  }
}

两个搜索请求是否不相同?

1 个答案:

答案 0 :(得分:1)

问题是您的映射不允许令牌与索引中存在的令牌不同。

在您的kibana查询中:

GET _search
{
  "query": {
    "query_string": {
      "query": "PDB_W2237.docx", 
      "default_operator": "AND"
    }
  }
}

您正在查询 PDB_W2237.docx ,但在NEST中,您正在查询 DB_W2237.docx

如果要查询 DB_W2237.docx 并期望结果,则可能必须将分析器从默认应用于默认a possible candidate depends on your usecase的标准分析器中更改。