弹性搜索 “index-template” 映射定义(copy_to?)

huangapple go评论44阅读模式
英文:

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"
          }
        }
      }
    ]
  }
}

huangapple
  • 本文由 发表于 2023年6月9日 00:16:30
  • 转载请务必保留本文链接:https://go.coder-hub.com/76433872.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定