{
"settings": {
"index": {
"mapping": {
"ignore_malformed": "true",
"include_type_name": "true"
}
}
},
"mappings": {
"properties": {
"address": {
"type": "text",
"field": {
"type": {
"type": "keyword"
},
"ip": {
"type": "ip"
},
"comment": {
"analyzer": "whitespace",
"type": "text"
}
}
}
}
}
错误:
elasticsearch.exceptions.RequestError: RequestError(400, 'mapper_parsing_exception', "无法解析 ID 为 'UA7RSHUBK7u8_ZjU0JQR' 的文档中 [text] 类型的字段 [address]
** **
这是我的代码和错误信息。 如何修复此映射 json? 你认为是什么原因造成的? 感谢您的回复。
最佳答案
The include_type_name parameter in the index creation, index template, and mapping APIs will default to false. Setting the parameter at all will result in a deprecation warning from Elasticsearch 7.x
fields
设置允许对同一索引中的同名字段有不同的设置。
修改后的索引映射为:
{
"settings": {
"index": {
"mapping": { <-- note this
"ignore_malformed": "true"
}
}
},
"mappings": {
"properties": {
"address": {
"type": "text",
"fields": { <-- note this
"type": {
"type": "keyword"
},
"ip": {
"type": "ip"
},
"comment": {
"analyzer": "whitespace",
"type": "text"
}
}
}
}
}
}
请参阅 Elasticsearch 官方文档 fields了解更多。
添加一个工作示例,其中包含索引数据、索引映射(与上面给出的相同)、搜索查询和搜索结果。
索引数据:
{
"address":"Khajrana circle"
}
{
"address":"indore"
}
{
"address":"192.168.1.1"
}
搜索查询:
{
"query": {
"multi_match": {
"query": "indore",
"fields": [
"address",
"address.type",
"address.comment"
]
}
}
}
搜索结果:
"hits": [
{
"_index": "64455730",
"_type": "_doc",
"_id": "1",
"_score": 1.0925692,
"_ignored": [
"address.ip"
],
"_source": {
"address": "indore"
}
}
]
关于elasticsearch - 如何创建具有多类型字段的 Elasticsearch 索引?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64455730/