Elasticsearch 1.4 升級 2.3.4

es1.x到es2.x有很大的差異,具體看https://www.elastic.co/guide/en/elasticsearch/reference/2.3/breaking-changes-2.0.html。下面羅列一些主要的變化點。html

1._id  path廢棄:

"_id":{
            "path」:"productId"
        }

之前這種寫法,在索引的時候不須要指定_id的值,es自動會把productId的值賦給_id,可是在2.3.4版本中廢棄了,因此索引的時候須要顯示的指定_id,不指定的話會默認生成一個值。json

2.「path」:「just name」廢棄:

 "productSkn": {
                "fields": {
                    "productSkn": {
                        "type": "string",
                        "index":    "not_analyzed",
                        "doc_values": true,
                        "fielddata": {
                            "format": "doc_values"
                        }
                    },
                    "productSkn_ansj": {
                        "type": "string",
                        "store": false,
                        "index_analyzer": "mmseg_complex",
                        "search_analyzer": "mmseg_complex"
                    }
                },
                "type": "multi_field",
                "path": "just_name"
            }

這種寫法配置了 "path": 「just_name」後若是想對productSkn_ansj進行查詢,能夠數據結構

{
    "match" : {
        「productSkn_ansj" : 「xxx"
    }
}

可是在2.3.4版本中廢除了 "path": 「just_name」,查詢productSkn_ansj的時候必須得full name,得這樣寫:elasticsearch

{
    "match" : {
        「productSkn.productSkn_ansj" : 「xxx"
    }
}

3.index_analyzer廢棄:

使用analyzer代替,若是index analyzer跟search analyzer同樣的話不須要寫search_analyzer,直接寫一個analyzer就好了。ide

4.doc_value fielddata變動:

not analyzer字段doc_value有效,默認爲trueui

analyzer字段fielddata有效,默認爲truespa

doc_value、fielddata都是爲了聚合計算、排序、在腳本中訪問字段值而引入的數據結構,是根據反向索引再次反向出來的一個正向索引,也就是文檔到關鍵詞的映射。插件

doc_value是落磁盤的,是預先構建的,也就是構建文檔索引的時候。code

fielddata是放內存的,是在一個字段在作聚合、排序、在腳本中訪問的時候構建的(命中就不構建了)。orm

5.Muticast Discovery變動:

Muticast Discovery默認不可用,須要安裝相應的插件

6.Filtered Query

這個已經 deprecated,在 2.x 中你還能夠用。可是建議作以下修改

{
  "query": {
    "filtered": {
      "query": {
       …….
      },
      "filter": {
        …….
      }
    }
  }
}

修改成 

{
  "query": {
    "bool": {
      "must": {
       …….
      },
      "filter": {
        …….
      }
    }
  }
}

把 query 和 filter 移到 bool 查詢的 must 和 filter 參數之中。

7.字段名不要有dot(點)

8.optimize使用force merge接口代替

9.啓動es不能使用root,須要建立非root用戶啓動es

10.multi field

     1.4版本

"brandNameCn": {
    "fields": {
        "brandNameCn": {
            "type": "string",
            "store": false,
            "analyzer": "ik_complex",
            "search_analyzer": "ik_complex",
            "copy_to":  ["searchField","searchField_ansj"]
        },
        "brandNameCn_pinyin": {
             "type": "string",
            "store": false,
            "analyzer": "pinyin_analyzer",
            "search_analyzer": "standard"
        }
    },
    "type": "multi_field"
}

   2.3.4版本

{
  "brandNameCn": {
    "copy_to": [
      "searchField", "searchField_ansj"],
    "analyzer": "ik_complex",
    "type": "string",
    "fields": {
      "brandNameCn_pinyin": {
        "search_analyzer": "standard",
        "analyzer": "pinyin_analyzer",
        "type": "string"
      }
    }
  }
}

11.refresh_interval

1.4版本         refresh_interval=1

2.3.4版本      refresh_interval=1s

相關文章
相關標籤/搜索