Es query+aggs handles problems with spaces and horizontal bars

Environment:
es:2.4
brand Type is string
under query+aggs query will get three records: Best , Choice , Products , the three record teams have brand values, and the others are all the same. Elasticsearch splits Best Choice Products into three parts.

the following is the query statement:

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

the following is part of the result
clipboard.png

Mar.28,2021

es aggregates string types for term after word segmentation. If you want to aggregate the original value, use subfields to set a type without word segmentation, and then analyze the aggregation for that type

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

ide/en/elasticsearch/reference/1.4/_multi_fields.html" rel=" nofollow noreferrer "> https://www.elastic.co/guide/.

Menu