0

当我使用 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 Hits。

这是命中中 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
              }
            }
          }
        }
      }
    }
  }
}

这两个搜索请求不一样吗?

4

1 回答 1

1

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

在您的 kibana 查询中:

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

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

如果您想查询DB_W2237.docx并期待结果,那么您可能必须将分析器从默认应用的标准分析器更改为其他可能的候选对象,具体取决于您的用例

于 2018-07-15T12:30:20.223 回答