I am confused by the ES docs, in fact here they state the the indexes must go in the mapping dir (and indexname sub dirs):
Mappings can be defined within files called [mapping_name].json and be placed either under config/mappings/_default location, or under config/mappings/[index_name] (for mappings that should be associated only with a specific index).
But then here in the "config" section, it states:
Index templates can also be placed within the config location (path.conf) under the templates directory (note, make sure to place them on all master eligible nodes). For example, a file called template_1.json can be placed under config/templates and it will be added if it matches an index.
I put my mapping in /config/mappings/myindexname/mappinfile.json
and it is like:
{ "template": "maincontentindex", "settings": { "index": { "analysis": { "analyzer": { "htmlStrippingAnalyzer": { "tokenizer": "standard", "filter": ["standard", "lowercase"], "char_filter": "html_strip" } } } } }, "mappings": { "rendition": { "_timestamp": { "enabled": true, "store" : true }, "properties": { "key": { "type": "string", "store": "yes", "analyzer": "keyword" }, "parentPage": { "type": "string", "store": "yes", "analyzer": "keyword" }, "type": { "type": "string", "store": "yes", "analyzer": "keyword" }, "language": { "type": "string", "store": "yes", "analyzer": "keyword" }, "device": { "type": "string", "store": "yes", "analyzer": "keyword" }, "territory": { "type": "string", "store": "yes", "analyzer": "keyword" }, "channel": { "type": "string", "store": "yes", "analyzer": "keyword" }, "template": { "type": "string", "store": "yes", "analyzer": "keyword" }, "meta": { "properties": { "content": { "type": "string", "store": "yes" } } } } } } }
if I use the REST Api to put it in the server it works fine and if I call /maincontentindex/rendition/_mapping I just get the above structure (even with no data).
But with the directory I just get a 404 and if I insert anything it's just the usual dynamic mapping.
You can use the update mapping API to add new properties to an existing object field. To see how this works, try the following example. Use the create index API to create an index with the name object field and an inner first text field. Use the update mapping API to add a new inner last text field to the name field.
Mapping is the process of defining how a document, and the fields it contains, are stored and indexed. Each document is a collection of fields, which each have their own data type. When mapping your data, you create a mapping definition, which contains a list of fields that are pertinent to the document.
These can be accessed from your dashboard by choosing Stack Settings > Elasticsearch . The next step is to write a a curl -x get command to retrieve the mappings from Elasticsearch. You will be returned with a json output similar to the below screenshot.
There is a difference between mappings and templates.
Mappings contain your fields and how you want to index/store them in elasticsearch. They refer to a specific index and type (or multiple types in the same index when using the _default_
special type). You can submit mappings either while creating an index through the create index api, or through the put mapping api to modify the mappings for an existing index.
Index templates are a way to automatically apply mappings and index settings to indices that are going to be created in the future, whose names match a specified pattern. Let's say that mappings are a part of an index template. An index template can contains mappings for multiple types and index settings too.
If you have an index template, you can put it under templates
as mentioned in the reference. If you have a mapping for a type, you need to put it under the mappings
directory.
The json that you pasted into the question is an index template, which needs to go under the templates
folder, not under the mappings
one. What you get back using the get mapping api as described is not the template itself as you said but the current mapping for the index/type that you specified in the url (only the mappings part of your template).
Also, I would suggest you to use the REST api that elasticsearch provides. Using files on file system doesn't really look like the elasticsearch way of doing things.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With