英文:
Elastic search "index-template" mapping definition (copy_to?)
问题
I want to set mapping definition for the indexes, where I could perform (in the my site UI) a text search in the whole document (not case sensitive), a text search in each separate field (not case sensitive), and also sort by each field (there are all numbers or strings).
我想为索引设置映射定义,在我的站点用户界面中,我想执行整个文档的文本搜索(不区分大小写),在每个单独的字段中执行文本搜索(不区分大小写),并且还可以按每个字段进行排序(这些字段都是数字或字符串)。
Is this the right way of doing that? by using dynamic_template
and providing him:
这是正确的做法吗?通过使用dynamic_template
并提供以下内容:
[
{
"strings_as_keyword": {
"match_mapping_type": "string",
"mapping": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
}
}
},
{
"numbers_as_double": {
"match_mapping_type": "long",
"mapping": {
"type": "double"
}
}
}
]
Should I maybe use copy_to
for the full document search?
我是否应该使用copy_to
来进行完整文档的搜索?
英文:
I'm defining an index template for documents, which have unknown number of fields (the fields themselves are unknown as well).
I want to set mapping definition for the indexes, where I could perform (in the my site UI) a text search in the whole document (not case sensitive), a text search in each separate field (not case sensitive), and also sort by each field (there are all numbers or strings).
Is this the right way of doing that? by using dynamic_template
and providing him:
[
{
"strings_as_keyword": {
"match_mapping_type": "string",
"mapping": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
}
}
},
{
"numbers_as_double": {
"match_mapping_type": "long",
"mapping": {
"type": "double"
}
}
}
]
Should I maybe use copy_to
for the full document search?
答案1
得分: 1
Tldr;
是的,如果您计划在许多字段中进行大量搜索,最好将所有这些字段汇总到一个字段中。
Solution:
PUT 76433872
{
"mappings": {
"dynamic_templates": [
{
"strings_as_text": {
"match_mapping_type": "string",
"path_unmatch": "all_text",
"mapping": {
"type": "text",
"copy_to": "all_text"
}
}
}
]
}
}
英文:
Tldr;
Yes, if you plan on heavily search through lots of fields you are better of aggregating all those fields in a single one.
Solution:
PUT 76433872
{
"mappings": {
"dynamic_templates": [
{
"strings_as_text": {
"match_mapping_type": "string",
"path_unmatch": "all_text",
"mapping": {
"type": "text",
"copy_to": "all_text"
}
}
}
]
}
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论