我是 ElasticSearch 的新手,正在尝试执行他们主页中提到的示例,但我遇到了这个错误 -
{
"error": {
"root_cause": [
{
"type": "illegal_argument_exception",
"reason": "unknown setting [index.mappings.employee.properties.age.type] please check that any required plugins are installed, or check the breaking changes documentation for removed settings"
}
],
"type": "illegal_argument_exception",
"reason": "unknown setting [index.mappings.employee.properties.age.type] please check that any required plugins are installed, or check the breaking changes documentation for removed settings",
"suppressed": [
{
"type": "illegal_argument_exception",
"reason": "unknown setting [index.mappings.employee.properties.experience.type] please check that any required plugins are installed, or check the breaking changes documentation for removed settings"
},
{
"type": "illegal_argument_exception",
"reason": "unknown setting [index.mappings.employee.properties.name.analyzer] please check that any required plugins are installed, or check the breaking changes documentation for removed settings"
},
{
"type": "illegal_argument_exception",
"reason": "unknown setting [index.mappings.employee.properties.name.type] please check that any required plugins are installed, or check the breaking changes documentation for removed settings"
}
]
},
"status": 400
}
post请求的url&body如下-
网址-> http://localhost:9200/company body ->
{
"settings": {
"index": {
"number_of_shards": 1,
"number_of_replicas": 1
},
"analysis": {
"analyzer": {
"analyzer-name": {
"type": "custom",
"tokenizer": "keyword",
"filter": "lowercase"
}
}
},
"mappings": {
"employee": {
"properties": {
"age": {
"type": "long"
},
"experience": {
"type": "long"
},
"name": {
"type": "string",
"analyzer": "analyzer-name"
}
}
}
}
}
}
如何修复错误?
最佳答案
您的 JSON 正文对象的语法有两个错误:
- 节点
settings
必须只有两个 child :index
和analysis
。节点mappings
必须是根级的。 - 字段
name
的类型string
无效,它必须是text
或keyword
。因为你需要分析这个字段,所以在你的情况下它应该是text
。
因此 ES 版本 6.x 的工作查询(在提出问题时是最新的)应该是这样的:
{
"settings": {
"index": {
"number_of_shards": 1,
"number_of_replicas": 1
},
"analysis": {
"analyzer": {
"analyzer-name": {
"type": "custom",
"tokenizer": "keyword",
"filter": "lowercase"
}
}
}
},
"mappings": {
"employee": {
"properties": {
"age": {
"type": "long"
},
"experience": {
"type": "long"
},
"name": {
"type": "text",
"analyzer": "analyzer-name"
}
}
}
}
}
从ES 7.0版本开始,映射类型was removed来自索引定义,所以上面的查询在 ES 7.x 中不起作用。
ES 版本 7.x 的工作查询可能有两种类型:
如果索引应该只包含关于员工的数据,您可以简单地删除
employee
映射类型,查询将如下所示:{ "settings": { "index": { "number_of_shards": 1, "number_of_replicas": 1 }, "analysis": { "analyzer": { "analyzer-name": { "type": "custom", "tokenizer": "keyword", "filter": "lowercase" } } } }, "mappings": { "properties": { "age": { "type": "long" }, "experience": { "type": "long" }, "name": { "type": "text", "analyzer": "analyzer-name" } } } }
如果索引应该包含关于员工的数据和一些其他数据,您可以使用
employee
作为object type 的字段查询将是这样的:{ "settings": { "index": { "number_of_shards": 1, "number_of_replicas": 1 }, "analysis": { "analyzer": { "analyzer-name": { "type": "custom", "tokenizer": "keyword", "filter": "lowercase" } } } }, "mappings": { "properties": { "employee": { "properties": { "age": { "type": "long" }, "experience": { "type": "long" }, "name": { "type": "text", "analyzer": "analyzer-name" } } } } } }
关于ElasticSearch::Exception 同时创建索引和文档,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52001376/