在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/Java/ es query+aggs 對(duì)空格,橫杠處理問題

es query+aggs 對(duì)空格,橫杠處理問題

環(huán)境:
es:2.4
brand類型為 string
下面 query+aggs 查詢會(huì)得出三條記錄,分別是Best,Choice,Products,三條記錄隊(duì)了brand值,其他都相同,elasticsearch 把 Best Choice Products 拆分成三部分進(jìn)行分別聚合,同樣包含橫杠如Best-Choice-Products,情況也一樣
如果把query條件去除,則不會(huì)出現(xiàn)上述情況,求解!

以下是查詢語句:

 {
    "size": 0,
    "aggs": {....},
    "query": {
        "filtered": {
            "filter": {
                "bool": {
                    "must": [
                        {
                            "match": {
                                "brand": {
                                    "query": "Best Choice Products",
                                    "type": "phrase"
                                }
                            }
                        }
                    ]
                }
            }
        }
    }
}

以下是結(jié)果的部分
clipboard.png

回答
編輯回答
萌面人

es 對(duì) string 類型的聚合是針對(duì)分詞后的 term 進(jìn)行的,如果你想對(duì)原始值做聚合,使用子字段設(shè)置一個(gè)不分詞的類型,然后針對(duì)該類型進(jìn)行聚合分析

PUT /my_index
{
  "mappings": {
    "my_type": {
      "properties": {
        "city": {
          "type": "string",
          "fields": {
            "raw": { 
              "type":  "string",
              "index": "not_analyzed"
            }
          }
        }
      }
    }
  }
}

https://www.elastic.co/guide/...

2018年6月27日 22:51