【问题标题】:Where do I put the mapping files for Elasticsearch?我应该将 Elasticsearch 的映射文件放在哪里?
【发布时间】:2013-09-22 05:08:50
【问题描述】:

我对 ES 文档感到困惑,事实上 here 他们声明索引必须放在映射目录(和索引名子目录)中:

映射可以在名为 [mapping_name].json 的文件中定义,并且可以 放置在 config/mappings/_default 位置下,或下 config/mappings/[index_name] (用于应该关联的映射 仅具有特定索引)。

然后here 在“配置”部分中声明:

索引模板也可以放在配置位置 (path.conf) 在模板目录下(注意,一定要放置 它们在所有符合条件的主节点上)。例如,一个名为 template_1.json 可以放在 config/templates 下,它将是 如果匹配索引则添加。

我将我的映射放在/config/mappings/myindexname/mappinfile.json 中,它就像:

{
    "template": "maincontentindex",
    "settings": {
        "index": {
            "analysis": {
                "analyzer": {
                    "htmlStrippingAnalyzer": {
                        "tokenizer": "standard",
                        "filter": ["standard", "lowercase"],
                        "char_filter": "html_strip"
                    }
                }
            }
        }
    },

    "mappings": {
        "rendition": {
            "_timestamp": {
                "enabled": true,
                "store" : true
            },
            "properties": {
                "key": {
                    "type": "string",
                    "store": "yes",
                    "analyzer": "keyword"
                },
                "parentPage": {
                    "type": "string",
                    "store": "yes",
                    "analyzer": "keyword"
                },
                "type": {
                    "type": "string",
                    "store": "yes",
                    "analyzer": "keyword"
                },
                "language": {
                    "type": "string",
                    "store": "yes",
                    "analyzer": "keyword"
                },
                "device": {
                    "type": "string",
                    "store": "yes",
                    "analyzer": "keyword"
                },
                "territory": {
                    "type": "string",
                    "store": "yes",
                    "analyzer": "keyword"
                },
                "channel": {
                    "type": "string",
                    "store": "yes",
                    "analyzer": "keyword"
                },
                "template": {
                    "type": "string",
                    "store": "yes",
                    "analyzer": "keyword"
                },
                "meta": {
                    "properties": {
                        "content": {
                            "type": "string",
                            "store": "yes"
                        }
                    }
                }       
            }
        }
    }
}

如果我使用 REST Api 将它放在服务器中,它工作正常,如果我调用 /maincontentindex/rendition/_mapping,我只会得到上述结构(即使没有数据)。

但是对于目录,我只会得到一个 404,如果我插入任何内容,它只是通常的动态映射。

【问题讨论】:

  • Ftr: (至少)as of ES 5.1 “不再可以在配置目录中的文件中指定映射。相反,应该使用 API 创建映射”。我强烈认为模板也是如此。

标签: json elasticsearch


【解决方案1】:

映射和模板之间是有区别的。

Mappings 包含您的字段以及您希望如何在弹性搜索中索引/存储它们。它们引用特定的索引和类型(或使用 _default_ 特殊类型时同一索引中的多个类型)。您可以在创建索引时通过create index api 提交映射,也可以通过put mapping api 修改现有索引的映射。

Index templates 是一种自动将映射和索引设置应用于将要创建的索引的方法,这些索引的名称与指定的模式匹配。假设映射是索引模板的一部分。索引模板也可以包含多种类型的映射和索引设置。

如果你有一个索引模板,你可以把它放在templates 下,如参考中所述。如果你有一个类型的映射,你需要把它放在mappings 目录下。

您粘贴到问题中的json是一个索引模板,它需要放在templates文件夹下,而不是mappings文件夹下。您使用所描述的 get mapping api 返回的不是您所说的模板本身,而是您在 url 中指定的索引/类型的当前映射(仅模板的映射部分)。

另外,我建议您使用 elasticsearch 提供的 REST api。在文件系统上使用文件看起来并不像 elasticsearch 的做事方式。

【讨论】:

  • 当我在等待答案时,我已经解决了 :) 只有一件事不起作用......在编写映射时,我将设置部分放在哪里?
  • 设置不适合映射 :) 您必须单独使用更新设置 api。我不知道可以将索引设置放在文件系统上的地方。然后我会使用可以包含映射和设置的索引模板。
  • 我最终做到了。感恩!
  • 为什么不鼓励使用文件?拥有配置文件更容易实现自动化部署和版本控制,也很容易通过在文本编辑器中打开文件来读取当前配置。我总是想知道有多少人只使用带有弹性搜索的休息 API。部署已知配置的新集群时,如何使用 REST API 设置配置?
猜你喜欢
  • 1970-01-01
  • 2014-03-04
  • 2016-03-08
  • 2015-09-05
  • 1970-01-01
  • 2010-12-01
  • 2018-09-28
  • 2019-10-04
  • 1970-01-01
相关资源
最近更新 更多