【问题标题】:"index": "not_analyzed" in elasticsearch“索引”:弹性搜索中的“未分析”
【发布时间】:2016-09-04 07:00:09
【问题描述】:

我已经使用 cmd 删除映射

curl -XDELETE 'http://localhost:9200/logstash_log*/'

在我的 conf 中,我将索引定义如下,

output {
   elasticsearch {
   hosts => localhost
   index => "logstash_log-%{+YYYY.MM.dd}"
 }

并尝试创建一个新的映射,但我得到了错误

 #curl -XPUT http://localhost:9200/logstash_log*/_mapping/log -d '

{


     "properties":{
          "@timestamp":"type":"date","format":"strict_date_optional_time||epoch_millis"},
           "message":{"type":"string"},
           "host":{"type":"ip"},
           "name":{"type":"string","index": "not_analyzed"},
           "type":{"type":"string"}
                }

}'

{"error":{"root_cause":[{"type":"index_not_found_exception","re​​ason":"没有这样的索引","re​​source.type":"index_or_alias","re​​source.id":" logstash_log*","index":"logstash_log*"}],"type":"index_not_found_exception","re​​ason":"没有这样的索引","re​​source.type":"index_or_alias","re​​source.id":" logstash_log*","index":"logstash_log*"},"status":404}

我该如何解决? 任何帮助将不胜感激!

【问题讨论】:

    标签: elasticsearch mapping


    【解决方案1】:

    您需要像这样重新创建索引:

    # curl -XPUT http://localhost:9200/logstash_log -d '{
      "mappings": {
        "log": {
          "properties": {
            "@timestamp": {
              "type": "date",
              "format": "strict_date_optional_time||epoch_millis"
            },
            "message": {
              "type": "string"
            },
            "host": {
              "type": "ip"
            },
            "name": {
              "type": "string",
              "index": "not_analyzed"
            },
            "type": {
              "type": "string"
            }
          }
        }
      }
    }'
    

    虽然看起来您正在从 logstash 创建每日索引,但您最好还是创建一个模板。将以下内容存储在index_template.json

    {
      "template": "logstash-*",
      "mappings": {
        "log": {
          "properties": {
            "@timestamp": {
              "type": "date",
              "format": "strict_date_optional_time||epoch_millis"
            },
            "message": {
              "type": "string"
            },
            "host": {
              "type": "ip"
            },
            "name": {
              "type": "string",
              "index": "not_analyzed"
            },
            "type": {
              "type": "string"
            }
          }
        }
      }
    }
    

    然后像这样修改你的logstash配置:

    output {
       elasticsearch {
       hosts => localhost
       index => "logstash_log-%{+YYYY.MM.dd}"
       manage_template => true
       template_name => "logstash"
       template => "/path/to/index_template.json"
       template_overwrite => true
    }
    

    【讨论】:

    • @stefansaye 有这个运气吗?
    【解决方案2】:

    * 是索引名称的无效字符。

    索引名称不能包含以下字符 [\, /, *, ?, \", , |, , ,]

    【讨论】:

      猜你喜欢
      • 2014-09-02
      • 1970-01-01
      • 2021-02-03
      • 1970-01-01
      • 2016-05-20
      • 2016-10-24
      相关资源
      最近更新 更多