【问题标题】:Writing Elasticsearch Nest Bool query with Must Field value使用 Must Field 值编写 Elasticsearch Nest Bool 查询
【发布时间】:2020-05-01 15:08:57
【问题描述】:

我正在尝试重现以下在 Kibana 中运行良好的查询:

{
  "query": {
    "bool": {
      "must": [
        {
          "match": {
            "title": "fake"
          }
        }
      ],
      "filter": {
        "term": {
          "roleIds": "af54122f-8d99-47e5-9e5a-88659a1229d4"
        }
      }
    }
  }
}

这是我在 .NET 中的尝试:

ISearchResponse<T> response = await client.SearchAsync<T>(s => s
    .Query(q => q
        .Bool(b => b
            .Must(m => m
                .Match(t => t
                    .Field(new Field("title"))
                    .Value("fake") // "Value" is red.
                ))
        .Filter(f => f
            .Term(t => t
                .Field(new Field("roleIds")).Value(RoleId))) // Value works here.
          )); 

价值在这里不起作用。编译错误是:

Error   CS1061  'MatchQueryDescriptor<T>' does not contain a definition for 'Value' and no accessible extension method 'Value' accepting a first argument of type 'MatchQueryDescriptor<T>' could be found (are you missing a using directive or an assembly reference?)

如何写出bool &gt; must &gt; match &gt; title: val的等价物?

【问题讨论】:

    标签: elasticsearch .net-core nest


    【解决方案1】:

    只需将.Value("fake") 替换为.Query("fake")。作为旁注,您可以将.Field(new Field("title")) 简化为.Field("title")

    希望对您有所帮助。

    【讨论】:

      猜你喜欢
      • 2016-06-06
      • 1970-01-01
      • 1970-01-01
      • 2022-01-20
      • 2015-04-30
      • 1970-01-01
      • 2016-10-11
      • 1970-01-01
      • 2015-06-05
      相关资源
      最近更新 更多