The ways don't index several fields

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?

        },
        "a" : {
          "type" : "text",
          "index" : false,
          "norms" : false
        },
        "b" : {
          "type" : "keyword",
          "ignore_above" : 1024
        },
        "c" : {
          "type" : "text",
          "index" : false,
          "norms" : false
        },

I found three different mapping parameters and not sure which is the right one to use.

index: false
index: no
enabled: false

Regards // Hugo

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

"index": false

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

"dynamic": false

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.

Nate

2 Likes

Hi @nateynate ,

This is great information. I’m reading your post now.
Thanks for the explanation.

Hugo

1 Like

Just happy to be of service, @hugok! Good luck!

I’m getting errors on OS 1.3.2:

Mapping definition for [content] has unsupported parameters: [index : false]" 

when attempting to use above solution of: “index” = false. Instead, I am opting to use use “dynamic” = false

@nateynate I read your blog Fine Dining for Indices. Great article. I have been reviewing OpenSearch (and even Elasticsearch documentation) relevant to index:false. In your example in your article:

"dont_index_me": {
                "type": "text",
                "index": false
            }

What is the benefit of specifying a type (in this case text) if you are specifically configuring this element to not be indexed?

I appreciate your feedback. I’m sure the answer was glaring at me in the documentation and I simply overlooked it.

Thank you.

Max Friz

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.)

Thanks for the mention!

Nate