简体   繁体   English

在现有索引中创建一个新字段 - ElasticSearch

[英]Creating a new field into existing index - ElasticSearch

I am wanting to create a new field and add it to an existing index so that way I can send a unique value to that new field.我想创建一个新字段并将其添加到现有索引中,这样我就可以向该新字段发送唯一值。 I was hoping there was an API to do this without having to do it in the CLI of Kibana.我希望有一个 API 可以做到这一点,而不必在 Kibana 的 CLI 中进行。 But I ran into this article that tells you how to add new fields to an existing index.但是我遇到了这篇文章,它告诉您如何向现有索引添加新字段。

I tried to add it under _source field but it did not allow me.我试图将它添加到_source字段下,但它不允许我。

PUT customer-simulation-es-app-logs-development-2021-07/_mapping
{
  "_source":{
    "TransactionKey":{
      "type": "keyword"
    }
  }
}

So I then added it to properties which allowed me:所以我然后将它添加到允许我的properties中:

PUT customer-simulation-es-app-logs-development-2021-07/_mapping
{
  "properties":{
    "TransactionKey":{
      "type": "keyword"
    }
  }
}

To make sure it was updated I ran the cmd GET customer-simulation-es-app-logs-development-2021-07/_mapping which did return it.为了确保它已更新,我运行了 cmd GET customer-simulation-es-app-logs-development-2021-07/_mapping确实返回了它。

{
  "customer-simulation-es-app-logs-development-2021-07" : {
    "mappings" : {
      "properties" : {
        "@timestamp" : {
          "type" : "date"
        },
        "TransactionKey" : {
          "type" : "keyword"
        },
        "exceptions" : {
          "properties" : {
            "ClassName" : {
              "type" : "text",
              "fields" : {
                "keyword" : {
                  "type" : "keyword",
                  "ignore_above" : 256
                }
              }
            },
.....

But when I go to Discover and type in TransactionKey for the fields nothing pops up.但是当我去 Discover 并为这些字段输入 TransactionKey 时,什么也没有弹出。 Did I not add the new field correctly to the existing index?我是否没有将新字段正确添加到现有索引中?

If you're running a version prior to 7.11, then you need to go to Stack Management > Index pattern and refresh your index pattern before seeing your new field in the Discover view.如果您运行的是 7.11 之前的版本,那么您需要转到堆栈管理 > 索引模式并刷新索引模式,然后才能在“发现”视图中看到您的新字段。 You need to do this every time your index mapping changes.每次索引映射更改时都需要执行此操作。

Since 7.11, the index pattern are being refreshed automatically whenever needed.从 7.11 开始,索引模式会在需要时自动刷新

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM