After Elasticsearch, uses ik participle, the result of the aggregate query is lowercase letters?

When the value of the

field is" AA", the result of the aggregate query is" how does aa", get the original value?

make the following query:

POST /113/_search
{
  "query": {
    "query_string": {
      "query": "Jack"
    }
  }, 
    "aggs" : {
      "gender" : {
        "terms" : {
        "field" : "gender"
        }
      },
      "grade" : {
        "terms" : {
            "field" : "grade",
            "order" : {"_count" : "asc"}
        }
      }
    }
}

get the result:

{
  "hits": {
    "total": 4,
    "max_score": 1.3862944,
    "hits": [
      {
        "_index": "113",
        "_type": "default_type",
        "_id": "1",
        "_score": 0.07419574,
        "_source": {
          "name": "Tome Jack",
          "grade": "AA",
          "gender": 1
        }
      }
    ]
  },
  "aggregations": {
    "grade": {
      "doc_count_error_upper_bound": 0,
      "sum_other_doc_count": 0,
      "buckets": [
        {
          "key": "b",
          "doc_count": 1
        },
        {
          "key": "c",
          "doc_count": 1
        },
        {
          "key": "aa",
          "doc_count": 2
        }
      ]
    }
  }
}
The

grade field is set as follows

      "grade": {
        "type": "text",
        "fields": {
          "keyword": {
            "type": "keyword"
          }
        },
        "analyzer": "ik_max_word",
        "fielddata": true
      },
The value of the

grade field has been changed in the aggregate query. How to get the original value?

Mar.03,2021

when the query is grouped, it is processed with the keyword type, otherwise it will be grouped according to the result of the participle. Earlier versions of ES did not prompt for exceptions in this way, but they did so from the beginning of ES5, and Significant Terms Aggregation is recommended for handling.

according to your description, it should be understood that the grade field is grouped in full text, and the grouping field of grade is set to grade.keyword. This piece is rewritten as:

POST /113/_search
{
  "query": {
    "query_string": {
      "query": "Jack"
    }
  }, 
    "aggs" : {
      "gender" : {
        "terms" : {
        "field" : "gender"
        }
      },
      "grade" : {
        "terms" : {
            "field" : "grade.keyword",
            "order" : {"_count" : "asc"}
        }
      }
    }
}
Menu