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

时间:2018-05-27 06:30:25

标签: elasticsearch elasticsearch-net

拥有这样的数据:{ "id" : 22, "name" : "test", "tagIds" : [ 2, 35, 56, 59 ] },如何搜索名称标记

使用以下查询:

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

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

如何在流利的巢中正确写出这个?

1 个答案:

答案 0 :(得分:1)

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

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