【问题标题】:elasticsearch NEST client, filed with attribute "not_analyzed" still be analyzed when search keywords contains hyphenelasticsearch NEST 客户端,当搜索关键字包含连字符时,仍会分析属性为“not_analyzed”的文件
【发布时间】:2014-10-07 19:50:32
【问题描述】:

我有一个名为“IndexModel”的类:

public class IndexModel
{
    [ElasticProperty(Index= FieldIndexOption.NotAnalyzed, Store = true)]
    public string ModelNumber{ get; set; }
}

以下是我如何设置弹性客户端:

var uri = new Uri("http://localhost:9200");
var config = new ConnectionSettings(uri);
var client = new ElasticClient(config);
client.Map<IndexModel>(m => m.MapFromAttributes());

我可以从响应中看到映射结果:

Request {
"indexmodel": {
"properties": {

  "modelNumber": {
    "type": "string",
    "store": true,
    "index": "not_analyzed"
     },
    }
  }
}

我有一个该类型的索引记录,“ModelNumber”属性的值为“test-123”,以下是我的查询:

var result = client.Search<IndexModel>(s => s.Query(new TermQuery() { Field = Property.Path<IndexModel>(it => it.ModelNumber), Value = "test-123"}));

这是我得到的最终映射请求:

Method: POST, 
Url: http://localhost:9200/_search, 
Request: {
  "query": {
    "term": {
      "modelNumber": {
        "value": "test-123"
      }
    }
  }
}

但是我无法得到结果,如果我将“ModelNumber”属性的值更改为“test123”,重新索引它,并通过关键字“test123”搜索它,那么它是有效的,所以我认为分析器仍然分析了“ModelNumber”属性,谁能帮帮我,谢谢。

【问题讨论】:

  • 我确实有类似的问题,升级到最新的 NEST 包后。 @Dragon 你有运气吗?
  • 这个问题解决了吗?

标签: c# elasticsearch nest


【解决方案1】:

我遇到了同样的问题,解决方法是先创建索引,然后放映射,最后添加数据。

将类型属性添加到您的模型字段

 [ElasticProperty(OmitNorms = true, Index = FieldIndexOption.NotAnalyzed)]

        var node = new Uri("http://192.168.0.56:9200/");
        var settings = new ConnectionSettings(node, defaultIndex: "ticket");
        var client = new ElasticClient(settings);

        var createIndexResult = client.CreateIndex("ticket");
        var mapResult = client.Map<TicketElastic>(c => c.MapFromAttributes().IgnoreConflicts().Type("TicketElastic").Indices("ticket"));

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-07-09
    • 1970-01-01
    • 2020-12-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-20
    • 1970-01-01
    相关资源
    最近更新 更多