我是 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
}
Run Code Online (Sandbox Code Playgroud)
post请求的url和body如下-
URL -> 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"
}
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
如何修复错误?
Ale*_*kov 12
您的 JSON 正文对象的语法有两个错误:
settings必须只有两个孩子:index和analysis。节点mappings必须是根级。name类型无效string,必须是textor 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"
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
从 ES 7.0 版本开始,映射类型从索引定义中删除,因此上面的查询在 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"
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
如果索引应该包含有关员工的数据和其他一些数据,您可以使用employeeas对象类型的字段,查询将如下所示:
{
"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"
}
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7548 次 |
| 最近记录: |