【问题标题】:elastic search returning no results filtering on multi value field弹性搜索在多值字段上返回无结果过滤
【发布时间】:2019-12-11 20:46:39
【问题描述】:

我在弹性搜索中有一个名为 category 的字段,它包含多个值。以下是样本值

"category": [
                    "Commercial",
                    "CafeBarRestaurant",
                    "Tables"
                ],

现在我正在查询弹性搜索以获取类别为“商业”的文档。以下是我的查询:

{
 "from":0,
 "size":40,
 "query":{
  "bool":{
     "filter":[
        {
           "bool":{
              "must":[
                 {
                    "term":{
                       "category":{
                          "value":"Commercial",
                          "boost":1.0
                       }
                    }
                 }
              ],
              "adjust_pure_negative":true,
              "boost":1.0
           }
        }
     ],
     "adjust_pure_negative":true,
     "boost":1.0
  }

} } 映射:

{
"products": {
    "mappings": {
        "category": {
            "full_name": "category",
            "mapping": {
                "category": {
                    "type": "text",
                    "fields": {
                        "keyword": {
                            "type": "keyword",
                            "ignore_above": 256
                        }
                    }
                }
            }
        }
    }
}

}

每次它都给我空的结果。任何人都可以向我建议查询中有什么问题。 谢谢。

【问题讨论】:

标签: elasticsearch


【解决方案1】:

你不需要布尔值。试试:

{
  "query: {
      "match": {
          "category": "Commercial"}}  }

或:

{
  "query: {
      "term": {
          "category.keyword": "Commercial"}}  }

【讨论】:

  • 我还需要在聚合上添加更多过滤器,所以我使用的是 bool
  • 能否请您发布您的索引映射?
猜你喜欢
  • 1970-01-01
  • 2016-07-28
  • 1970-01-01
  • 2012-06-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-12-09
  • 2012-03-06
相关资源
最近更新 更多