> For the complete documentation index, see [llms.txt](https://xiaoxiami.gitbook.io/elasticsearch/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://xiaoxiami.gitbook.io/elasticsearch/ji-chu/mapping/323mapping-parametersff08-ying-she-can-shu-ff09/3232-normalizergui-yi-531629.md).

# normalizer(归一化)

[`keyword`](https://www.elastic.co/guide/en/elasticsearch/reference/5.3/keyword.html) **fields**（关键字字段） 的 `normalizer（`归一化）属性与 [`analyzer`](https://www.elastic.co/guide/en/elasticsearch/reference/5.3/analyzer.html)`（`分析器）类似,只不过它保证 **analysis chain**（分析链）生成单一的 `token（词元`）.

`normalizer（`归一化）应用于索引 **keyword**（关键字）之前,以及诸如在 [`match`](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-match-query.html)`query`(匹配查询),查询解析器搜索 **keyword fields**（关键字字段）的时候.

```
curl -XPUT 'localhost:9200/index?pretty' -H 'Content-Type: application/json' -d'
{
  "settings": {
    "analysis": {
      "normalizer": {
        "my_normalizer": {
          "type": "custom",
          "char_filter": [],
          "filter": ["lowercase", "asciifolding"]
        }
      }
    }
  },
  "mappings": {
    "type": {
      "properties": {
        "foo": {
          "type": "keyword",
          "normalizer": "my_normalizer"
        }
      }
    }
  }
}
'
curl -XPUT 'localhost:9200/index/type/1?pretty' -H 'Content-Type: application/json' -d'
{
  "foo": "BÀR"
}
'
curl -XPUT 'localhost:9200/index/type/2?pretty' -H 'Content-Type: application/json' -d'
{
  "foo": "bar"
}
'
curl -XPUT 'localhost:9200/index/type/3?pretty' -H 'Content-Type: application/json' -d'
{
  "foo": "baz"
}
'
curl -XPOST 'localhost:9200/index/_refresh?pretty'
curl -XGET 'localhost:9200/index/_search?pretty' -H 'Content-Type: application/json' -d'
{
  "query": {
    "match": {
      "foo": "BAR"
    }
  }
}
'
```

上述查询与 **documents（文档） 1**和**2**相匹配,这是因为在索引和查询的时候都将 `BAR`转换为了 `bar`.

```
{
  "took": $body.took,
  "timed_out": false,
  "_shards": {
    "total": 5,
    "successful": 5,
    "failed": 0
  },
  "hits": {
    "total": 2,
    "max_score": 0.2876821,
    "hits": [
      {
        "_index": "index",
        "_type": "type",
        "_id": "2",
        "_score": 0.2876821,
        "_source": {
          "foo": "bar"
        }
      },
      {
        "_index": "index",
        "_type": "type",
        "_id": "1",
        "_score": 0.2876821,
        "_source": {
          "foo": "BÀR"
        }
      }
    ]
  }
}
```

此外,**keywords** 在索引之前转换意味着聚合返回 **normalised values**（归一化的值）:

```
curl -XGET 'localhost:9200/index/_search?pretty' -H 'Content-Type: application/json' -d'
{
  "size": 0,
  "aggs": {
    "foo_terms": {
      "terms": {
        "field": "foo"
      }
    }
  }
}
'
```

返回

```
{
  "took": 43,
  "timed_out": false,
  "_shards": {
    "total": 5,
    "successful": 5,
    "failed": 0
  },
  "hits": {
    "total": 3,
    "max_score": 0.0,
    "hits": []
  },
  "aggregations": {
    "foo_terms": {
      "doc_count_error_upper_bound": 0,
      "sum_other_doc_count": 0,
      "buckets": [
        {
          "key": "bar",
          "doc_count": 2
        },
        {
          "key": "baz",
          "doc_count": 1
        }
      ]
    }
  }
}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://xiaoxiami.gitbook.io/elasticsearch/ji-chu/mapping/323mapping-parametersff08-ying-she-can-shu-ff09/3232-normalizergui-yi-531629.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
