在 Docker 构建期间定义弹性搜索映射



我有一个MySQL,Logstash和ES设置,但我需要将一些字段设置为关键字类型而不是文本。我读到在Logstash(logstash.conf(中不可能做到这一点,所以需要在ES中完成。我在这里遵循了一个类似的问题,并稍微修改了它以放置映射,但我得到了这个错误:"stacktrace": ["org.elasticsearch.bootstrap.StartupException: java.lang.IllegalArgumentException: unknown setting [es.path.data] please check that any required plugins are installed, or check the breaking changes documentation for removed settings",

我正在使用 docker-compose 在同一网络下一次启动所有服务,因此必须在 logstash 将数据移植到 ES 之前指定映射。(无法在非空索引上更改映射(。

我看过其他问题,它们看起来确实有点旧,所以我想问一下现在是否有更好的方法来做到这一点。

我的mapping.json

{
"mappings": {
"properties": {
"authors": {"type": "keyword"},
"tags": {"type": "keyword"}
}
}
}

Dockerfile

FROM elasticsearch:7.5.1
COPY ./docker-entrypoint.sh .
COPY ./mapping.json .
RUN mkdir /data && chown -R elasticsearch:elasticsearch /data && echo 'es.path.data: /data' >> config/elasticsearch.yml && echo 'path.data: /data' >> config/elasticsearch.yml
ADD https://raw.githubusercontent.com/vishnubob/wait-for-it/e1f115e4ca285c3c24e847c4dd4be955e0ed51c2/wait-for-it.sh /utils/wait-for-it.sh
# Copy the files you may need and your insert script
RUN ./docker-entrypoint.sh elasticsearch -p /tmp/epid & /bin/bash /utils/wait-for-it.sh -t 0 localhost:9200 -- curl -X PUT 'http://localhost:9200/cnas_publications' -d @./mapping.json; kill $(cat /tmp/epid) && wait $(cat /tmp/epid); exit 0;

编辑:我在这里使用了官方存储库中的 docker-entrypoint.sh

看来我弄错了,实际上可以在 Logstash 中定义映射。假设您使用的是官方的 elasticsearch 镜像,请创建一个 ES 模板,并用它制作一个卷到 logstash 容器中。

这是我的logstash.conf输出的示例

output {
stdout { codec => "rubydebug" }
elasticsearch {
hosts => "http://elasticsearch:9200"
index => "test"
template => "/logstash/mapping.json"
template_name => "mapping"
document_id => "%{[@metadata][_id]}"
}
}

并且不要忘记在 ES 模板中设置index_patterns

最新更新