1

我正在尝试在 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"}前者中没有该字段?

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

4

1 回答 1

1

您需要从映射中删除它

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

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

于 2020-06-02T08:18:08.510 回答