我有一个非常简单的ElasticSearch模型:
[ElasticsearchType(RelationName = "example")]
public class ElasticModel
{
[Text(Name = "description", Analyzer = "Russian", Index = true, SearchAnalyzer = "Russian")]
public string Description { get; set; }
}
然后我在下一行取消索引:protected ICreateIndexRequest ConfigureIndex(CreateIndexDescriptor indexDescriptor,
Func<IndexSettingsDescriptor, IPromise<IIndexSettings>> selectorOfIndexSettings)
{
ICreateIndexRequest returnValue;
returnValue = indexDescriptor.Settings(selectorOfIndexSettings);
return returnValue;
}
await _client.Indices.CreateAsync(completeIndexName, indexDescriptor => ConfigureIndex(indexDescriptor, selector));
然后通过下一个值初始化我的模型,然后尝试搜索:var document = new ElasticModel()
{
Description = "В Москве все выходные будут дожди"
};
var responseDoc = await await _client.IndexAsync(new IndexRequest<T>(document, completeIndexName))
var responseSearch = await _client.SearchAsync<ElasticModel>(s => s.Index(completeIndexName)
.Query(q => q.QueryString(c => c
.Query("выходной")
)));
但结果为空。当我向Elasticsearch服务器发出下一个请求时:
POST {{ElasticSearchAddress}}/_analyze
{
"analyzer": "russian",
"text": "В Москве все выходные будут дожди"
}
我看到了预期的结果:{
"tokens": [
{
"token": "москв",
"start_offset": 2,
"end_offset": 8,
"type": "<ALPHANUM>",
"position": 1
},
{
"token": "выходн",
"start_offset": 13,
"end_offset": 21,
"type": "<ALPHANUM>",
"position": 3
},
{
"token": "будут",
"start_offset": 22,
"end_offset": 27,
"type": "<ALPHANUM>",
"position": 4
},
{
"token": "дожд",
"start_offset": 28,
"end_offset": 33,
"type": "<ALPHANUM>",
"position": 5
}
]
}
谁能解释我,为什么我从C#代码中搜索时不使用俄语分析器,并且不返回我预期的结果?更新:
要求/ elastictest100 / _search
与 body :
{
"query": {
"multi_match" : {
"query": "выходные будут",
"fields": [ "description" ],
"analyzer": "russian"
}
}
}
还给我:{
"took": 2,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"skipped": 0,
"failed": 0
},
"hits": {
"total": {
"value": 3,
"relation": "eq"
},
"max_score": 0.13353139,
"hits": [
{
"_index": "mediadev-elastictest100",
"_type": "_doc",
"_id": "G2FzRnMBhdWoY2X4fmQo",
"_score": 0.13353139,
"_source": {
"description": "В Москве все выходные будут дожди"
}
},
{
"_index": "mediadev-elastictest100",
"_type": "_doc",
"_id": "HGGLRnMBhdWoY2X4AGSV",
"_score": 0.13353139,
"_source": {
"description": "В Москве все выходные будут дожди"
}
},
{
"_index": "mediadev-elastictest100",
"_type": "_doc",
"_id": "HWGMRnMBhdWoY2X4tGSY",
"_score": 0.13353139,
"_source": {
"description": "В Москве все выходные будут дожди"
}
}
]
}
}
与 body :{
"query": {
"multi_match" : {
"query": "выходной будет",
"fields": [ "description" ],
"analyzer": "russian"
}
}
}
还给我:{
"took": 1,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"skipped": 0,
"failed": 0
},
"hits": {
"total": {
"value": 0,
"relation": "eq"
},
"max_score": null,
"hits": []
}
}
最佳答案
我对Nest代码不熟悉,但是可以给您一些提示来调试问题。
最容易检查搜索JSON,并使用ES REST端点直接对您的索引进行命中以查看根本原因。
关于elasticsearch - 使用俄语文本分析器搜索不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62869474/