【问题标题】:ElasticSearch - Change mapping to a fieldElasticSearch - 将映射更改为字段
【发布时间】:2017-05-13 17:48:41
【问题描述】:

我正在使用弹性搜索集群版本 1.7.2,并尝试更改其中一个字段的映射(我认为)以忽略此字符:'-'

该字段为“Request.Headers.Host”,其值可以包含“-”,如: “app-cdn.cap.com”

#curl -X GET http://10.2.5.181:9200?pretty
{
  "status" : 200,
  "name" : "log-zone-a",
  "cluster_name" : "cap-logs",
  "version" : {
    "number" : "1.7.2",
    "build_hash" : "e43676b1385b7f593f7202acbd816e8ec",
    "build_timestamp" : "2015-09-14T09:49:53Z",
    "build_snapshot" : false,
    "lucene_version" : "4.10.4"
  },
  "tagline" : "You Know, for Search"
}

我看到它与参数not_analyzed有关,并且根据我在网上找到的内容,我尝试了这个:

#curl -X PUT '{"mappings":{"logs":{"properties":{"Request.Headers.Host":{"type":"string","index":"not_analyzed"}}}}}' http://10.2.5.181:9200/logstash-2016.12.27/logs/_mapping?pretty
curl: (3) [globbing] nested braces not supported at pos 13
{
  "error" : "ActionRequestValidationException[Validation Failed: 1: mapping source is empty;]",
  "status" : 400
}
#curl -H 'Accept: application/json' -X PUT http://10.2.5.181:9200/logstash-2016.12.27?pretty -d @/home/moses/mapping.json
{
  "error" : "RemoteTransportException[[log-zone-b][inet[/10.2.105.181:9300]][indices:admin/create]]; nested: IndexAlreadyExistsException[[logstash-2016.12.27] already exists]; ",
  "status" : 400
}

#cat /home/moses/mapping.json | jq .
{
  "logstash-2016.12.27": {
    "mappings": {
      "logs": {
        "properties": {
          "Request.Headers.Host": {
            "type": "string",
            "index": "not_analyzed"
          }
        }
      }
    }
  }
}

当我更改映射并对不存在的索引执行相同操作时,它成功但索引似乎错误,将“Request.Headers.Host”与点分开:(

#cat /home/moses/mapping.json
{"Request.Headers.Host":{"type":"string","index":"not_analyzed"}}

    #curl -H 'Accept: application/json' -X PUT http://10.2.5.181:9200/logstash-2016.12.30?pretty -d @/home/moses/mapping.json
    {
      "acknowledged" : true
    }

#curl -H 'Accept: application/json' -X GET http://10.2.5.181:9200/logstash-2016.12.30?pretty
{
"logstash-2016.12.30" : {
"aliases" : { },
"mappings" : { },
"settings" : {
  "index" : {
    "creation_date" : "1483011476137",
    "Request" : {
      "Headers" : {
        "Host" : {
          "type" : "string",
          "index" : "not_analyzed"
        }
      }
    },
    "uuid" : "M6Ly0wvwTGu1aulSViYcPg",
    "number_of_replicas" : "1",
    "number_of_shards" : "5",
    "version" : {
      "created" : "1070299"
    }
  }
},
"warmers" : { }
  }
}

如何将这种映射配置设置为当前索引和未来索引?

谢谢, 摩西

【问题讨论】:

  • 您无法更新现有字段的映射。您在这里有两个解决方法 1) 使用更新的映射重新索引整个数据。但请确保在索引数据之前放置映射。 2) 在现有索引中添加新的not_analyzed 字段。 Reference -1 , Reference-2
  • @rvheddeg 我在创建仪表板时遇到连字符问题,kibana 将以下值解析为:“Request.Headers.Host”:“app-cdn.cap.com”作为两个值:“应用程序”和“cdn.cap.com”

标签: logging elasticsearch logstash kibana elastic-stack


【解决方案1】:

要正确设置“Request.Headers.Host”等内部字段的映射,您必须定义多个级别:

{
  "logs" : {
    "properties" : {
      "Request" : {
        "properties" : {
          "Headers" : {
            "properties": {
              "Host": {
               "type" : "string",
               "index": "not_analyzed"
              }
            }
          }
        }
      }
    }
  }
}

【讨论】:

  • 感谢@AlainCollins!我在 ES 中很菜鸟,如何将此映射永久保存到未来的索引?
  • 要为未来索引设置映射,请使用template
  • 感谢@AlainCollins 如何为特定索引设置默认映射(例如:logstash-2016.02.01)?我需要该索引的默认值将是“not_analyzed”而不指定每个字段。
  • 对于一个索引,您将设置映射(在创建索引之前)。但是,如果您有这样的每日索引,您将需要一个模板。要使所有字符串未分析,您可以使用动态映射。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-11-23
  • 1970-01-01
  • 2012-08-31
  • 1970-01-01
  • 2017-10-13
  • 2017-05-18
  • 1970-01-01
相关资源
最近更新 更多