【问题标题】:Elastic NEST using Term filter on text field with inner keyword field弹性 NEST 在具有内部关键字字段的文本字段上使用术语过滤器
【发布时间】:2017-11-09 22:01:13
【问题描述】:

我正在尝试按照 Elastic 5.x 上的新标准对访问其内部关键字字段的文本属性执行 Term 过滤器...

我有这样一个属性:

{
  "foo": {
    "type" "text",
    "fields": {
      "keyword": {
        "type": "keyword",
        "ignore_above": 256
      }
    }
  }
}

我正在运行以下代码以使用内部关键字字段进行过滤...

var searchResult = _elasticClient.Search<InvoiceResult>(x => x
 .Index("my_index")
 .Query(query => query
  .Term(term => term
   .Field(new Field("foo.keyword"))
   .Value("TEST")
  )
 )
);

有没有什么方法可以使用模型类达到相同的结果?当我尝试下面的代码时,它从不使用关键字内部字段。

var searchResult = _elasticClient.Search<InvoiceResult>(x => x
 .Index("my_index")
 .Query(query => query
  .Term(term => term
   .Field(field => field.Foo)
   .Value("TEST")
  )
 )
);

干杯!

【问题讨论】:

    标签: .net elasticsearch nest


    【解决方案1】:

    NEST has 这种情况下非常方便的扩展方法。

    var searchResult = _elasticClient.Search<InvoiceResult>(x => x
        .Index("my_index")
        .Query(query => query
            .Term(term => term
                .Field(field => field.Foo.Suffix("keyword"))
                .Value("TEST")
            )
        )
    );
    

    希望对您有所帮助?。

    【讨论】:

    • 谢谢!我花了很长时间才弄清楚我认为微不足道的事情。
    猜你喜欢
    • 2015-07-11
    • 2013-07-28
    • 1970-01-01
    • 2019-08-10
    • 1970-01-01
    • 2022-12-13
    • 1970-01-01
    • 2012-12-30
    • 1970-01-01
    相关资源
    最近更新 更多