Elasticsearch.Net 和 NEST 搜索字符串和标签数组

Elasticsearch.Net and NEST to search both for a string and array of tags

有这样的数据:{ "id" : 22, "name" : "test", "tagIds" : [ 2, 35, 56, 59 ] },怎么可能同时搜索 nametags

使用以下查询:

{
  "from": 0,
  "size": 100,  
  "query": {
    "terms": {
      "tagIds": [
        35
      ]
    },  
    "multi_match": {
      "query": "test",
      "fields": [
        "name"
      ]
    }
  }
}

获取此解析异常:[terms] malformed query, expected [END_OBJECT] but found [FIELD_NAME]

如何在 fluent nest 中正确书写?

您需要使用 bool query 来合并多个查询。因此,您的查询应如下所示:

{   
    "from": 0,  
    "size": 100,     
    "query": {
        "bool": {
            "must": [
                {
                    "terms": {
                        "tagIds": [
                            35
                        ]
                    }
                },
                {
                    "multi_match": {
                        "query": "test",
                        "fields": [
                            "name"
                        ]
                    }
                }
            ]
        }
    }
}