天天看點

elasticsearch建立索引 ,mapping,dynamic_templates

簡述

elasticsearch 建立索引時通常需要配置mapping。mapping的含義類似于關系資料庫中的表結構。但mapping更加靈活。

建立

以下執行個體是建立索引:my-index-000001,并加入dynamic_templates。

位址

http://localhost

:9400/my-index-000001

方式

put

端口

http 端口

模闆内容

{
  "mappings": {
    "_default_": {
     "dynamic_templates": [
          {
            "string_fields": {
              "match": "*",
              "match_mapping_type": "string",
              "mapping": {
                "analyzer": "ik_max_word",
                "fields": {
                  "raw": {
                    "ignore_above": 2000,
                    "type": "keyword"
                  }
                },
                "index": "true",
                "omit_norms": true,
                "type": "text"
              }
            }
          }
        ],
          "properties": {
                    "amount": {
                        "type": "double"
                       
                    }
          }
    }
  }
}           

curl 方式

curl --location --request PUT 'http://localhost:9400/my-index-000001' \
--header 'Content-Type: application/json' \
--data-raw '{
  "mappings": {
    "_default_": {
     "dynamic_templates": [
          {
            "string_fields": {
              "match": "*",
              "match_mapping_type": "string",
              "mapping": {
                "analyzer": "ik_max_word",
                "fields": {
                  "raw": {
                    "ignore_above": 2000,
                    "type": "keyword"
                  }
                },
                "index": "true",
                "omit_norms": true,
                "type": "text"
              }
            }
          }
        ],
          "properties": {
                    "contract_amount": {
                        "type": "double"
                        
                    }
          }
    }
  }
}'           

總結

上面的模闆中配置了

amount

double

類型。分詞器:ik_max_word,查詢不分詞的屬性:raw