There is another very good feature in the mappings in es. Properties from the default type are automatically inherited by special types you define. Let’s assume the following json used to create an index.
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 52 53 54 55 56 57 58 |
{ "settings": { "mapper" : { "dynamic": false }, "index": { "analysis": { "analyzer": { "string_analyzer_index": { "type": "custom", "tokenizer": "standard", "filter": ["asciifolding", "lowercase", "name_ngram"] } }, "filter": { "name_ngram": { "type": "edgeNGram", "min_gram": 1, "max_gram": 20, "side": "front" } } } } }, "mappings": { "_default_": { "properties": { "generalProperty01": { "type": "object" }, "generalProperty02": { "type": "string" } }, "dynamic_templates": [ { "name_template": { "path_match": "generalProperty01.*", "mapping": { "type": "string", "include_in_all": false, "analyzer": "string_analyzer_index" } } } ] }, "mySpecialEntity01": { "properties": { "specialEntity01Property01": { "type": "string" } } }, "mySpecialEntity02": {} } } |
That creates an index with the following metadata.
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 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
{ state: open settings: { index.analysis.analyzer.string_analyzer_index.filter.0: asciifolding index.analysis.filter.name_ngram.max_gram: 20 index.analysis.filter.name_ngram.type: edgeNGram index.analysis.analyzer.string_analyzer_index.filter.2: name_ngram index.analysis.analyzer.string_analyzer_index.filter.1: lowercase index.analysis.analyzer.string_analyzer_index.tokenizer: standard index.mapper.dynamic: false index.analysis.filter.name_ngram.side: front index.analysis.analyzer.string_analyzer_index.type: custom index.analysis.filter.name_ngram.min_gram: 1 index.number_of_shards: 5 index.number_of_replicas: 1 index.version.created: 900099 } mappings: { mySpecialEntity02: { dynamic_templates: [ { name_template: { mapping: { include_in_all: false analyzer: string_analyzer_index type: string } path_match: generalProperty01.* } } ] properties: { generalProperty01: { type: object } generalProperty02: { type: string } } } _default_: { dynamic_templates: [ { name_template: { mapping: { include_in_all: false analyzer: string_analyzer_index type: string } path_match: generalProperty01.* } } ] properties: { generalProperty01: { type: object } generalProperty02: { type: string } } } mySpecialEntity01: { dynamic_templates: [ { name_template: { mapping: { include_in_all: false analyzer: string_analyzer_index type: string } path_match: generalProperty01.* } } ] properties: { generalProperty01: { type: object } generalProperty02: { type: string } specialEntity01Property01: { type: string } } } } aliases: [ ] } |
As you see the properties and dynamic templates are also present in the specialized types now.
loading...