ElasticSearch映射报错:Root mapping含不支持参数求助
ElasticSearch自定义Analyzer报错修复
问题根源
- 接口使用错误:你调用的
_mapping接口仅用于修改索引映射,无法添加或修改settings(自定义分析器属于索引设置,必须在创建索引时指定)。 - 类型参数无效:ElasticSearch 7及以上版本已移除索引类型(type),URL中的
article类型参数不符合当前版本规范。
修正后的操作步骤
1. 删除旧索引(若存在)
curl -XDELETE http://localhost:9200/articles
2. 创建带自定义分析器的索引
使用PUT /articles直接创建索引,同时定义settings和mappings:
curl -H "Content-Type: application/json" -XPUT http://localhost:9200/articles -d '{ "settings": { "analysis": { "analyzer": { "content_tokenizer": { "type": "standard", "tokenizer": "standard" }, "content_case_folding": { "type": "custom", "tokenizer": "standard", "filter": [ "lowercase" ] }, "content_stopword_removal": { "type": "custom", "tokenizer": "standard", "filter": [ "lowercase", "stop" ] }, "content_ngram_extraction": { "type": "custom", "tokenizer": "standard", "filter": [ "lowercase", "stop", "ngram" ] }, "content_stemmer": { "type": "custom", "tokenizer": "standard", "filter": [ "lowercase", "stop", "ngram", "stemmer" ] } }, "filter": { "ngram": { "type": "ngram", "min_gram": 2, "max_gram": 5 }, "stop": { "type": "stop", "stopwords": "_english_" }, "stemmer": { "type": "stemmer", "language": "english" } } } }, "mappings": { "properties": { "content": { "type": "text", "fields": { "tokenized": { "type": "text", "analyzer": "content_tokenizer" }, "case_folded": { "type": "text", "analyzer": "content_case_folding" }, "without_stopwords": { "type": "text", "analyzer": "content_stopword_removal" }, "ngrammed": { "type": "text", "analyzer": "content_ngram_extraction" }, "stemmed": { "type": "text", "analyzer": "content_stemmer" } } } } } }'
验证分析器
创建索引后,可通过_analyze接口测试自定义分析器是否正常工作:
curl -H "Content-Type: application/json" -XPOST http://localhost:9200/articles/_analyze -d '{ "analyzer": "content_stemmer", "text": "Hello world! This is a test of the stemmer filter." }'
内容的提问来源于stack exchange,提问作者Dee. Salako
相关产品推荐
相关产品推荐

