【问题标题】:Elasticsearch query for multiple fields terms and multile filelds must not match queryElasticsearch查询多字段术语和多字段不能匹配查询
【发布时间】:2021-05-03 02:58:54
【问题描述】:

我的要求如下:

  1. 我需要为 must_not 匹配条件使用多个字段
  2. 我需要在词条查询中使用多个字段

当我运行以下查询时,Must_not 出现以下错误

"reason": "[match] 查询不支持多个字段,找到了[app_rating] 和[satisfaction_rating]"

对于条款,多个字段也出现错误。

“原因”:“预期 [START_OBJECT] 在 [should] 下,但在 [MyBuckets] 中得到了 [START_ARRAY]”,

如何更正查询?

  "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"
      }
    }
  }
}

【问题讨论】:

  • 能否提供您的索引映射和示例文档,以便我提供工作示例。

标签: elasticsearch elasticsearch-aggregation elasticsearch-dsl


【解决方案1】:

您不能在单个 must_not 子句中使用多个字段,因此您必须添加多个 must_not 子句,您还尝试在各种术语上使用术语聚合,并且您的语法不正确导致异常.

您能否提供您的索引映射和示例文档,以便我提供工作示例。

【讨论】:

  • GET logstash-sdc-abt-memberfeedback/_search?您能否修改我的查询并在此重新分享会更有帮助。我对弹性搜索不太熟悉。请支持我。
  • 在此添加了示例数据。请检查以上
  • 亲爱的团队,有人可以帮我解决我的问题吗?我需要使用 3 个字段不能匹配和 3 个字段进行术语查询。我被困在查询中。请更正我的查询并帮助我解决这个问题。
  • @Prabhudas8703 您没有提供我在问题评论中询问的所需信息。
  • 请查看以上查询以获取示例映射文档。我在下面提到了主要查询
猜你喜欢
  • 2022-01-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-08-21
  • 2016-08-18
  • 2022-12-04
  • 2017-12-03
相关资源
最近更新 更多