anand.d
(anand dubey)
April 4, 2017, 1:54pm
1
I am using Elasticsearch 5.2.2. I have a requirement that in my index, some fields will be defined and some field will be dynamic. But the dynamic mapping is creating a structure something like this:
"COLOR": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
}
I don't want nested keyword field in dynamic mapping. Is there a way to supress it?
1 Like
dadoonet
(David Pilato)
April 4, 2017, 2:10pm
2
Define a template and force the behavior you want for text
fields.
anand.d
(anand dubey)
April 5, 2017, 4:31am
3
hi David,
Thank you for your reply. I tried using dynamic templates as shown below, but it doesn't seem to work:
PUT myindex
{
"settings" :
{
"analysis":
{
"analyzer":
{
"lowercasespaceanalyzer":
{
"type": "custom",
"tokenizer": "whitespace",
"filter": ["lowercase"]
}
}
}
},
"mappings" : {
"mytype" : {
"properties" : {
"extraction_date" : { "type" : "date",
"format": "MM-dd-yyyy HH:mm:ss"},
"markdown_price" : { "type" : "double" },
"regular_price" : { "type" : "double" },
"final_price" : { "type" : "double" }
},
"dynamic_templates": [
{
"strings_as_keywords": {
"match_mapping_type": "text",
"mapping": {
"type" : "text", "analyzer" : "lowercasespaceanalyzer", "tokenizer": "whitespace", "search_analyzer":"whitespace", "filter": ["lowercase"]
}
}
}
]
}
}
}
After this when i do get mapping, i am still getting dynamic fields with keyword as a nested element.
dadoonet
(David Pilato)
April 5, 2017, 4:45am
4
Can you give the result of GET _mapping?
Can you give the result of GET _template?
anand.d
(anand dubey)
April 5, 2017, 4:59am
5
hi David,
thanks for the quick reply. I am getting below as a result of get mapping:
{
"myindex": {
"mappings": {
"mytype": {
"dynamic_templates": [],
"properties": {
"24 hour timer": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"BRAND": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"COLOR": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
.....
anand.d
(anand dubey)
April 5, 2017, 5:00am
6
i don't want a nested keyword field as it will create extra field in index which will not be good for performance.
dadoonet
(David Pilato)
April 5, 2017, 5:25am
7
You can see that GET _mapping does not give the same result as your PUT myindex.
Did you really run the PUT request ? What is the result ?
anand.d
(anand dubey)
April 5, 2017, 5:32am
8
David i ran the put mapping which only generates mapping for the 4 fields. Rest all are dynamic fields which i am sending via java api. It has close to 1200 columns. After putting the data, i am seeing dynamic mapping fields like 'BRAND', 'COLOR' etc. which are stored as 'text' type but also have 'keyword' type as a nested structure. I dont want that, i only need 'text' type using dynamic template.
anand.d
(anand dubey)
April 5, 2017, 6:42am
9
it seems to be working using below code. I removed analyser and tokeniser from dynamic template:
PUT myindex
{
"settings" :
{
"index.mapping.total_fields.limit": 2000
},
"mappings" : {
"mytype" : {
"properties" : {
"extraction_date" : { "type" : "date",
"format": "MM-dd-yyyy HH:mm:ss"},
"markdown_price" : { "type" : "double" },
"regular_price" : { "type" : "double" },
"final_price" : { "type" : "double" }
},
"dynamic_templates": [
{
"strings_as_text": {
"match_mapping_type": "string",
"mapping": {
"type": "text"
}
}
}
]
}
}
}
1 Like
dadoonet
(David Pilato)
April 5, 2017, 9:48am
10
Ok great.
Please format your code using </>
icon as explained in this guide . It will make your post more readable.
Or use markdown style like:
```
CODE
```
system
(system)
Closed
May 3, 2017, 9:48am
11
This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.