Elasticsearch 动态加载属性的mapping

代码示例:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
  curl -XPUT 'localhost:9200/products' -d '{
    "settings": {
      "analysis": {
        "analyzer": {
          "pinyin_analyzer": {
            "tokenizer": "my_pinyin",
            "filter": ["standard", "nGram"]
          }
        },
        "tokenizer": {
          "my_pinyin": {
            "type": "pinyin",
            "first_letter": "prefix",
            "padding_char": ""
          }
        }
      }
    },
    "mappings": {
      "product": {
        "dynamic_templates": [
          {
            "property_template": {
              "path_match": "properties.*",
              "mapping": {
                "type": "multi_field",
                "fields": {
                  "{name}": {
                    "type": "string",
                    "analyzer" : "pinyin_analyzer",
                    "boost": 10,
                    "store": "no",
                    "term_vector": "with_positions_offsets"
                  },
                  "{name}_untouched": {
                    "type": "string",
                    "index": "not_analyzed"
                  }
                }
              }
            }
          }
        ]
      }
    }
  }'

  curl -XPOST 'localhost:9200/products/product' -d '{name: "加多宝", properties: {ping: 1} }'
  curl -XPOST 'localhost:9200/products/product' -d '{name: "水杯", properties: {ge: 1} }'

  curl -XGET 'localhost:9200/products/product/_mapping?pretty'

Comments

Copyright © 2017 kaka