【问题标题】:ElasticSearch: Weird problem in inserting documents to ElasticSearch indices when a template is presentElasticSearch:存在模板时将文档插入 ElasticSearch 索引的奇怪问题
【发布时间】:2020-06-02 08:15:30
【问题描述】:

我正在尝试在 ElasticSearch 中进行一些测试。我能够根据需要填充所有内容,但是每当我尝试放置我们项目的默认模板然后插入时,数据不会被摄取到索引中(尽管 http 调用是成功的)。

经过检查,我意识到即使使用 elasticSearch 的默认模板,我也无法插入一个简单的文档。 例如插入 ES 文档中的模板:

PUT _template/template_1
{
  "index_patterns": ["te*", "bar*"],
  "settings": {
    "number_of_shards": 1
  },
  "mappings": {
    "_source": {
      "enabled": false
    },
    "properties": {
      "host_name": {
        "type": "keyword"
      },
      "created_at": {
        "type": "date",
        "format": "EEE MMM dd HH:mm:ss Z yyyy"
      }
    }
  }
}

然后通过

index = "bark"中插入一个文档
PUT http://localhost:9200/bark/_doc/11232 HTTP/1.1
User-Agent: Fiddler
Host: localhost:9200
Content-Length: 21
Content-Type: application/json

{"host_name": "generic_name"}

在索引中添加一个文档,但没有关于 host_name 的数据。 只需将索引名称更改为该模板不适用的名称(如index = dark),就会添加一个包含有关host_name 的数据的文档。 显示用于复制的索引数据:

(当index=bark

{"took":2,"timed_out":false,"_shards":{"total":1,"successful":1,"skipped":0,"failed":0},"hits":{"total":{"value":1,"relation":"eq"},"max_score":1.0,"hits":[{"_index":"bark","_type":"_doc","_id":"11232","_score":1.0}]}}

(当index=dark

{"took":6,"timed_out":false,"_shards":{"total":1,"successful":1,"skipped":0,"failed":0},"hits":{"total":{"value":1,"relation":"eq"},"max_score":1.0,"hits":[{"_index":"dark","_type":"_doc","_id":"11232","_score":1.0,"_source":{"host_name":"generic_name"}}]}}

注意到前者没有_source":{"host_name":"generic_name"} 字段吗?

为此可以做些什么?如果有人遇到此问题或知道解决方法,请提供帮助。

【问题讨论】:

    标签: elasticsearch fiddler elasticsearch-7 elasticsearch-template


    【解决方案1】:

    您需要从映射中删除它

    "_source": {
      "enabled": false
    },
    

    此设置的效果是源文档不存储在_source字段中。这可能不是你想要的。

    【讨论】:

    • 嗨,这似乎不是问题。我试图让"enabled": true 并完全删除字段"_source": { "enabled": false } 两者都没有任何区别
    • 模板修改后是否删除了索引?
    • 是的,这就是问题所在。谢谢!
    • 太棒了,很高兴它有帮助!
    猜你喜欢
    • 2014-03-06
    • 2019-03-18
    • 2020-09-30
    • 1970-01-01
    • 2011-12-30
    • 1970-01-01
    • 1970-01-01
    • 2021-07-29
    • 2016-11-09
    相关资源
    最近更新 更多