简体   繁体   English

Elasticsearch 查询多字段术语和多字段不能匹配查询

[英]Elasticsearch query for multiple fields terms and multile filelds must not match query

My requirement is below:我的要求如下:

  1. I need to use multiple fields for must_not match conditions我需要为 must_not 匹配条件使用多个字段
  2. I need to use multiple fields in terms query我需要在术语查询中使用多个字段

When I run the below query, Getting the following error for Must_not当我运行以下查询时,Must_not 出现以下错误

"reason": "[match] query doesn't support multiple fields, found [app_rating] and [satisfaction_rating]" "reason": "[match] 查询不支持多个字段,找到 [app_rating] 和 [satisfaction_rating]"

And for the Terms multiple fields also getting the error.而对于条款多个字段也得到错误。

"reason": "Expected [START_OBJECT] under [should], but got a [START_ARRAY] in [MyBuckets]", "reason": "预计 [START_OBJECT] 在 [should] 下,但在 [MyBuckets] 中得到了 [START_ARRAY]",

How can I correct the query?如何更正查询?

  "size":0,
  "_source":["comments.keyword"],
    "query":{
    "bool": {
      "must": [
        {"match":{"source.keyword": "ONA"}}
      
      ],
    "must_not":[
      
      {"match":{"app_rating":"0","satisfaction_rating":"0","usability_rating": "0"}}
      ]
    }
},
"aggs": {
  "MyBuckets": {
    "should":[{
    "terms": {
      "fields": ["comments.keyword"]
    }
    },
    {
      "terms":{
        "fields": ["app_rating"]
      }
    },
    {
      "terms":{
        "fields": ["satisfaction_rating"]
      }
    },
    {
      "terms":{
        "fields": ["usability_rating"]
      }
      
    }
    ],
      "order":{
        "_count": "desc"
      },
      "size": "10"

}
}
}

** Below is the sample Mapping details**
'''{
  "mapping": {
    "properties": {
      "Id": {
        "type": "text",
        "fields": {
          "keyword": {
            "type": "keyword",
            "ignore_above": 256
}
        }
      },
      "app_rating": {
        "type": "long"
      },
"comments": {
        "type": "text",
        "fields": {
          "keyword": {
            "type": "keyword",
            "ignore_above": 256
          }
        }
      },
"conversation_rating": {
        "type": "long"
      },
      "id": {
        "type": "text",
        "fields": {
          "keyword": {
            "type": "keyword",
            "ignore_above": 256
}
        }
      },
      "satisfaction_rating": {
        "type": "long"
      },
"source": {
        "type": "text",
        "fields": {
          "keyword": {
            "type": "keyword",
            "ignore_above": 256
          }
        }
      },
"timestamp": {
        "type": "long"
      },
      "usability_rating": {
        "type": "long"
      }
    }
  }
}

You can't use multiple fields in a single must_not clause, so you have to add multiple must_not clause also you are trying to use terms aggregations on various terms and your syntax is not correct which is causing the exception.您不能在单个must_not子句中使用多个字段,因此您必须添加多个must_not子句,并且您正在尝试对各种术语使用术语聚合,并且您的语法不正确导致异常。

can you provide your index mapping and sample docs, so that I can provide the working example.您能否提供您的索引映射和示例文档,以便我提供工作示例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM