elasticsearch - 使用俄语文本分析器搜索不起作用

标签 elasticsearch nest elasticsearch-net

我有一个非常简单的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,以便您可以轻松地使用REST搜索端点进行测试,以比较是否生成正确的查询。
  • 匹配查询使用的是与索引时间相同的分析器,但没有分析词条查询,这会导致此类问题,并且在最终出现搜索结果时,应将索引时间标记与搜索时间标记匹配。

  • 最容易检查搜索JSON,并使用ES REST端点直接对您的索引进行命中以查看根本原因。

    关于elasticsearch - 使用俄语文本分析器搜索不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62869474/

    相关文章:

    elasticsearch - 在Elastic Search中找到从点到n个最近的多边形的距离?

    amazon-web-services - 如何在 AWS ES 中启用动态脚本?

    node.js - “NestMicroservice”错误地实现了接口(interface) 'INestMicroservice'

    elasticsearch - 读取geo_shape作为GeoJSON文本

    c# - ElasticSearch.Net-更新具有多个组件的数组

    c# - NEST Elasticsearch : how to return certain fields along with aggregated results?

    java - 如何使用ElasticSearch Rest高级客户端按任何字段中的任何单词进行搜索?

    java - JestClient 建议不要使用 java.lang.NoSuchMethodError

    elasticsearch - NEST是否支持更新索引分析?

    elasticsearch - 在elasticsearch中使用MinimumShouldMatch和术语查询