我在哪里放置弹性搜索的映射文件? [英] Where do I put the mapping files for Elasticsearch?

查看:94
本文介绍了我在哪里放置弹性搜索的映射文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对ES文档感到困惑,其实 here 他们声明索引必须在映射目录(和indexname子目录)中执行:

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


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

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).

但是,然后这里在config部分,它说:

But then here in the "config" section, it states:


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

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.

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

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

{
    "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 / _mapp我只是得到上面的结构(即使没有数据)。

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).

但是目录我只是得到一个404,如果我插入任何东西只是通常的动态映射。

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

推荐答案

映射和模板之间有区别。

There is a difference between mappings and templates.

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

Mappings contain 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 api to modify the mappings for an existing index.

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

Index templates are 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.

如果您有索引模板,可以将其放在 code>如参考文献所述。如果您有类型的映射,则需要将其放在映射目录下。

If you have an index template, you can put it under templates as mentioned in the reference. If you have a mapping for a type, you need to put it under the mappings directory.

你粘贴到这个问题是一个索引模板,它需要在模板文件夹下,不在映射之下。你所使用的get映射api所返回的不是你所说的模板本身,而是你在url中指定的索引/类型的当前映射(只有模板的映射部分)。

The json that you pasted into the question is an index template, which needs to go under the templates folder, not under the mappings one. 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).

此外,我建议您使用弹性搜索提供的REST api。在文件系统上使用文件看起来并不像弹性搜索方式那样。

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.

这篇关于我在哪里放置弹性搜索的映射文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆