为什么NEST ElasticClient没有找到文档



当我使用Kibana执行以下对Elasticsearch 的搜索请求时

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
}
}
}
}
}
}
}
}

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

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

在您的kibana查询中:

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

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

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

相关内容

  • 没有找到相关文章

最新更新