我会使用动态模板-它应该可以满足您的需求:
{ "testtemplates" : { "dynamic_templates" : [ { "template1" : { "match" : "*", "match_mapping_type" : "string", "mapping" : { "type" : "string", "index" : "not_analyzed" } } } ] }}有关此方法的更多信息,请参见:
https://www.elastic.co/guide/zh-CN/elasticsearch/guide/current/custom-
dynamic-mapping.html#dynamic-
templates
重要提示: 如果有人建议采用这种方法来解决 not_analyzed 问题,那么它将行不通! 关键字
分析器会对数据进行一些分析,然后将数据转换为小写字母。
例如
data: ElasticSearchRocks ==> Keyword Analyzer: elasticsearchrocks
自己尝试分析查询,看看它正在发生。
curl -XPUT localhost:9200/testindex -d '{ "index" : { "analysis" : { "analyzer" : { "default" : { "type" : "keyword" } } } }}'http://www.elasticsearch.org/guide/zh-
CN/elasticsearch/reference/current/analysis-keyword-
analyzer.html



