【问题标题】:Elasticsearch template field mapping not workingElasticsearch 模板字段映射不起作用
【发布时间】:2015-11-25 10:28:25
【问题描述】:

我为特定索引定义了以下模板:

curl -XPUT http://localhost:9200/_template/template_1 -d '{
"template": "new_dashboard_1",
"mappings": {
    "_default_" : {
   "_all" : {"enabled" : true},
   "dynamic_templates" : [ {
     "string_fields" : {
       "match" : "*",
       "match_mapping_type" : "string",
       "mapping" : {
         "type" : "string", "index" : "analyzed", "omit_norms" : true,
           "fields" : {
             "raw" : {"type": "string", "index" : "not_analyzed"}
           }
       }
     }
   }
  } ]
}
}'

我的意图是为任何字符串值创建一个 .raw 类型并将索引设置为“not_analyzed”..

但是当我创建一些测试数据并进行验证时,一开始并没有创建 .raw 字段。

curl -XPOST http://localhost:9200/new_dashboard_1/type/ -d '{
  "sensors": {
    "_reading": "26 Celsius",
    "_state": "Normal",
    "augmentation": {},
    "_slot": "7",
    "_name": "Temp: INLET"
  },
  "ipAddress": "10.0.0.2"
}'

curl -XGET http://localhost:9200/new_dashboard_1/type/_search?q=*:*                                                                                                                  

{
  "took": 35,
  "timed_out": false,
  "_shards": {
    "total": 5,
    "successful": 5,
    "failed": 0
  },
  "hits": {
    "total": 1,
    "max_score": 1,
    "hits": [
      {
        "_index": "new_dashboard_1",
        "_type": "type",
        "_id": "AVE-IUsW_nEkXpEfOb2D",
        "_score": 1,
        "_source": {
          "sensors": {
            "_reading": "26 Celsius",
            "_state": "Normal",
            "augmentation": {},
            "_slot": "7",
            "_name": "Temp: INLET"
          },
          "ipAddress": "10.0.0.2"
        }
      }
    ]
  }
}

有什么需要改变的吗?

【问题讨论】:

    标签: elasticsearch mapping elasticsearch-mapping elasticsearch-template


    【解决方案1】:

    raw 字段已创建,但它不是“可见的”,因为它没有添加到您发送用于索引的_source。但是,如果您在任何 raw 子字段上运行(例如)聚合,您会得到一些结果:

    {
      "size": 0,
      "aggs": {
        "ips": {
          "terms": {
            "field": "ipAddress.raw"
          }
        }
      }
    }
    

    此外,如果您在为文档编制索引后获得映射,您还会在其中看到 raw 字段:

    curl -XGET localhost:9200/new_dashboard_1/_mapping/type
    

    【讨论】:

    • 太棒了,很高兴你知道了!
    猜你喜欢
    • 2015-12-01
    • 1970-01-01
    • 2011-09-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多