【问题标题】:Elasticsearch NEST TranslationElasticsearch NEST 翻译
【发布时间】:2015-06-16 09:51:40
【问题描述】:

我的搜索给出了正确的结果并试图让它在 .NET Nest 中工作,但我似乎无法获得正确的语法。这是我拥有的 elastricsearch 查询:

{
  "query": {
    "filtered": { 
      "query": {
        "match": { "formattedName": "Michael" }
      },
      "filter": {
        "bool": {   
            "must": [
                { "term": { "projectId": "5022" } },
                { "term": { "isInvalid": "false" } }
            ]
        }
      }
    }
  }
}

在我的解决方案中,我有以下内容:

var lst = client.Search<EntitySearchItem>(s => s
    .Size(recordCount)
    .Index("entitysearch")
    .Filter(f => f
        .Bool(b => b
            .Must(m => m.Term("projectId", projectId), 
                m => m.Term("isInvalid", "false"))))
    .Query(q => q
        .Match(p => p.OnField(f => f.FormattedName).Query(name))));

有熟悉 Nest 的人知道我如何获得相同的结果吗?谢谢!

【问题讨论】:

  • 我也是 elasticsearch 新手,所以如果您有关于如何更好地格式化 json 查询的建议,我会很感激反馈。

标签: elasticsearch nest elasticsearch-net


【解决方案1】:

示例中的 elasticsearch 查询使用 filtered query。您可以像这样使用 NEST 创建一个:

var searchResponse = client.Search<EntitySearchItem>(s => s
    .Index("entitysearch")
    .Query(q => q
        .Filtered(f => f
            .Query(qq => qq
                .Match(m => m.OnField(field => field.FormattedName).Query(name)))
            .Filter(ff => ff.Bool(b => b
                .Must(m => m.Term(t => t.ProjectId, projectId), m => m.Term(t => t.IsInvalid, "false")))))));

我的EntitySearchItem 班级

public class EntitySearchItem
{
    public string ProjectId { get; set; }
    public string IsInvalid { get; set; }
    public string FormattedName { get; set; }
}

【讨论】:

  • 你是对的。那一定是模糊在一起了。
猜你喜欢
  • 2022-01-22
  • 1970-01-01
  • 2018-08-17
  • 1970-01-01
  • 2015-05-14
  • 2015-11-11
  • 2013-07-19
  • 2015-06-05
  • 2015-12-18
相关资源
最近更新 更多