鍍金池/ 問(wèn)答/Java  Linux  網(wǎng)絡(luò)安全/ Elasticsearch相同index不同type下的相同字段怎么設(shè)置不同的類(lèi)

Elasticsearch相同index不同type下的相同字段怎么設(shè)置不同的類(lèi)型?

Elasticsearch創(chuàng)建mapping的時(shí)候發(fā)現(xiàn)不同type的相同字段名稱(chēng)設(shè)置不同的type的是會(huì)報(bào)錯(cuò),所以請(qǐng)問(wèn)一下這種情況應(yīng)該怎么解決???

請(qǐng)求連接

 PUT  http://localhost:9200/new

參數(shù)如下:

{
    "max_result_window": "1000000",
    "_source" : {
        "enabled": true
      },
      "_all" : {
        "enabled": false
      },
    "mappings": {
         "type1": {
          "properties": {
            "@timestamp" : {
              "type" : "date"
            },
            "@version" : {
              "type" : "text",
              "fields" : {
                "keyword" : {
                  "type" : "keyword",
                  "ignore_above" : 256
                }
              }
            },
            "create_time" : {
              "index": "not_analyzed",
              "type" : "long"
            }
          }
        },
        "type2": {
          "properties": {
            "@timestamp" : {
              "type" : "date"
            },
            "@version" : {
              "type" : "text",
              "fields" : {
                "keyword" : {
                  "type" : "keyword",
                  "ignore_above" : 256
                }
              }
            },
            "create_time" : {
              "index": "not_analyzed",
              "type" : "date"
            }
          }
        }
    }
}
 

請(qǐng)求結(jié)果:

 {
    "error": {
        "root_cause": [
            {
                "type": "illegal_argument_exception",
                "reason": "mapper [create_time] cannot be changed from type [date] to [long]"
            }
        ],
        "type": "illegal_argument_exception",
        "reason": "mapper [create_time] cannot be changed from type [date] to [long]"
    },
    "status": 400
}
回答
編輯回答
鐧簞噯

可以使用嵌套對(duì)象,或者在子屬性設(shè)置成不同的那個(gè)類(lèi)型,但是一旦設(shè)定了,也是不能變的

2017年2月19日 08:54
編輯回答
互擼娃

這個(gè)是Elasticsearch規(guī)定死的,同一個(gè)索引內(nèi)的相同字段必須是相同類(lèi)型.

但是你可以曲線救國(guó),利用copy_to,復(fù)制到另一個(gè)字段里,使用不同的類(lèi)型

2017年1月26日 21:27