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

got*_*ch4 22 json elasticsearch

我对ES文档感到困惑,事实上他们在这里声明索引必须在映射dir(和indexname sub dirs)中:

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

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

索引模板也可以放在模板目录下的配置位置(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"
                        }
                    }
                }       
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

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

但是对于目录我只得到404,如果我插入任何东西,它只是通常的动态映射.

jav*_*nna 32

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

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

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

如果您有索引模板,则可以将其放在templates引用中所述的位置.如果您有类型的映射,则需要将其放在mappings目录下.

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

另外,我建议你使用elasticsearch提供的REST api.在文件系统上使用文件看起来并不像弹性搜索方式.

  • 为什么不鼓励使用文件?拥有配置文件对于自动部署和版本控制来说更容易,也可以通过在文本编辑器中打开文件来轻松读取当前配置.我总是想知道有多少人只使用带有elasticsearch的rest API.部署具有已知配置的新群集时,如何使用REST API设置配置? (4认同)