[英]how can i create elasticsearch index with multi type field?
{
"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', "failed to parse field [address] of type [text] in document with id 'UA7RSHUBK7u8_ZjU0JQR'
****
这是我的代码和错误消息。 如何修复此映射 json? 你认为是什么原因造成的? 感谢您的答复。
索引创建、索引模板和映射 API 中的include_type_name 参数将默认为 false。 完全设置该参数将导致 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 官方文档以了解更多信息。
添加一个包含索引数据、索引映射(与上面给出的相同)、搜索查询和搜索结果的工作示例。
索引数据:
{
"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"
}
}
]
mapper_parsing_exception
异常是由于各种原因导致 Elasticsearch 无法根据其映射正确解析文档时导致的异常,例如:如果在您的映射中定义了一个类型为object
的字段并尝试存储text
字段,则会提出类似的问题我在那里更详细地解释了它。
如您的错误消息中所述,您的文档 ID UA7RSHUBK7u8_ZjU0JQR
的address
字段格式不正确,您需要在问题中提供此 ID 的文档 JSON,并完成错误消息以进一步调试问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.