在 Elasticsearch 中,我可以设置语言特定的多字段吗?
In Elasticsearch, can I set language-specific multi-fields?
是否可以使用多字段设置查询多语言字段?
考虑这个映射:
PUT multi_test
{
"mappings": {
"data": {
"_field_names": {
"enabled": false
},
"properties": {
"book_title": {
"type": "text",
"fields": {
"english": {
"type": "text",
"analyzer": "english"
},
"german": {
"type": "text",
"analyzer": "german"
},
"italian": {
"type": "text",
"analyzer": "italian"
}
}
}
}
}
}
}
我尝试了以下方法,但它不起作用:
PUT multi_test/data/1
{
"book_title.english": "It's good",
"book_title.german": "Das gut"
}
该错误似乎表明我正在尝试添加新字段:
{ "error": { "root_cause": [ { "type": "mapper_parsing_exception",
"reason": "Could not dynamically add mapping for field
[book_title.english]. Existing mapping for [book_title] must be of
type object but found [text]." } ], "type":
"mapper_parsing_exception", "reason": "Could not dynamically add
mapping for field [book_title.english]. Existing mapping for
[book_title] must be of type object but found [text]." }, "status":
400 }
我做错了什么?
如果我的方法行不通,什么是更好的方法?
问题是您正在为 字段使用 using 字段 book_title。
- 当您想以多种方式保留相同的字段和数据时使用字段关键字,即使用不同的分析器或一些其他设置更改,但 fields.Here 下的所有字段名称中的值应该相同是 link描述什么是关键词字段https://www.elastic.co/guide/en/elasticsearch/reference/2.4/multi-fields.html
在您的用例中,映射应如下所示
放置multi_test
{
"mappings": {
"data": {
"_field_names": {
"enabled": false
},
"properties": {
"book_title": {
"properties": {
"english": {
"type": "text",
"analyzer": "english"
},
"german": {
"type": "text",
"analyzer": "german"
},
"italian": {
"type": "text",
"analyzer": "italian"
}
}
}
}
}
}
}
这会将 book_title 定义为对象类型,您可以在 book_title
下添加具有不同数据的多个字段
是否可以使用多字段设置查询多语言字段?
考虑这个映射:
PUT multi_test
{
"mappings": {
"data": {
"_field_names": {
"enabled": false
},
"properties": {
"book_title": {
"type": "text",
"fields": {
"english": {
"type": "text",
"analyzer": "english"
},
"german": {
"type": "text",
"analyzer": "german"
},
"italian": {
"type": "text",
"analyzer": "italian"
}
}
}
}
}
}
}
我尝试了以下方法,但它不起作用:
PUT multi_test/data/1
{
"book_title.english": "It's good",
"book_title.german": "Das gut"
}
该错误似乎表明我正在尝试添加新字段:
{ "error": { "root_cause": [ { "type": "mapper_parsing_exception", "reason": "Could not dynamically add mapping for field [book_title.english]. Existing mapping for [book_title] must be of type object but found [text]." } ], "type": "mapper_parsing_exception", "reason": "Could not dynamically add mapping for field [book_title.english]. Existing mapping for [book_title] must be of type object but found [text]." }, "status": 400 }
我做错了什么?
如果我的方法行不通,什么是更好的方法?
问题是您正在为 字段使用 using 字段 book_title。
- 当您想以多种方式保留相同的字段和数据时使用字段关键字,即使用不同的分析器或一些其他设置更改,但 fields.Here 下的所有字段名称中的值应该相同是 link描述什么是关键词字段https://www.elastic.co/guide/en/elasticsearch/reference/2.4/multi-fields.html
在您的用例中,映射应如下所示
放置multi_test
{
"mappings": {
"data": {
"_field_names": {
"enabled": false
},
"properties": {
"book_title": {
"properties": {
"english": {
"type": "text",
"analyzer": "english"
},
"german": {
"type": "text",
"analyzer": "german"
},
"italian": {
"type": "text",
"analyzer": "italian"
}
}
}
}
}
}
}
这会将 book_title 定义为对象类型,您可以在 book_title
下添加具有不同数据的多个字段