json 在哪里放置 Elasticsearch 的映射文件?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18855318/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 19:48:48  来源:igfitidea点击:

Where do I put the mapping files for Elasticsearch?

jsonelasticsearch

提问by gotch4

I am confused by the ES docs, in fact herethey state the the indexes must go in the mapping dir (and indexname sub dirs):

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

Mappings can be defined within files called [mapping_name].json and be placed either under config/mappings/_default location, or under config/mappings/[index_name] (for mappings that should be associated only with a specific index).

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

But then herein the "config" section, it states:

但后来这里的“配置”一节中,它指出:

Index templates can also be placed within the config location (path.conf) under the templates directory (note, make sure to place them on all master eligible nodes). For example, a file called template_1.json can be placed under config/templates and it will be added if it matches an index.

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

I put my mapping in /config/mappings/myindexname/mappinfile.jsonand it is like:

我把我的映射放进去/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"
                        }
                    }
                }       
            }
        }
    }
}

if I use the REST Api to put it in the server it works fine and if I call /maincontentindex/rendition/_mapping I just get the above structure (even with no data).

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

But with the directory I just get a 404 and if I insert anything it's just the usual dynamic mapping.

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

回答by javanna

There is a difference between mappings and templates.

映射和模板之间存在差异。

Mappingscontain your fields and how you want to index/store them in elasticsearch. They refer to a specific index and type (or multiple types in the same index when using the _default_special type). You can submit mappings either while creating an index through the create index api, or through the put mapping apito modify the mappings for an existing index.

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

Index templatesare a way to automatically apply mappings and index settings to indices that are going to be created in the future, whose names match a specified pattern. Let's say that mappings are a part of an index template. An index template can contains mappings for multiple types and index settings too.

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

If you have an index template, you can put it under templatesas mentioned in the reference. If you have a mapping for a type, you need to put it under the mappingsdirectory.

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

The json that you pasted into the question is an index template, which needs to go under the templatesfolder, not under the mappingsone. What you get back using the get mapping api as described is not the template itself as you said but the current mapping for the index/type that you specified in the url (only the mappings part of your template).

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

Also, I would suggest you to use the REST api that elasticsearch provides. Using files on file system doesn't really look like the elasticsearch way of doing things.

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