My document has fields a,b,c. The field b should be indexed and searchable. The a and c doesn’t need to be searchable. So I think it may save time to index each document by not indexing unnecessary fields such as fields a and c in the example. But I want them to be visible.
Is this the correct mapping setting?
Hi @hugok - I wrote a blog article about this a while back. What you’ve provided above looks correct. This might help clear up your confusion:
The short form is that to intentionally not index a field, you would provide
You’ll still be able to retrieve the source of the document if it is returned as a search result, but the field won’t be indexed.
One thing to keep in mind is that if you’re using a dynamic mapping on your index, it will create new mappings when it ingests a field that it hasn’t seen yet. To keep dynamic mappings from growing your indices, you can also use
inside of the mappings stanza. If you try to ingest a field for which there is no mapping, an error will take place.
TL:DR; It looks like you’ve done it right to me. Be aware of accidentally adding mappings by ingesting new fields.
Thanks for the question @maxfriz and I’m glad you liked the article.
I always like to provide a type for the field in case I ever want to re-index. Those values are still in the “source” of the document, so in the case of a reindex it will know what type - otherwise (not 100% sure) it will use dynamic typing and it may not get it right.)