0
0
ElasticsearchHow-ToBeginner · 3 min read

How to Set a Field as Not Searchable in Elasticsearch

To make a field not searchable in Elasticsearch, set "index": false in the field's mapping. This disables indexing for that field, so it won't appear in search results but can still be retrieved.
📐

Syntax

In Elasticsearch, you control whether a field is searchable by setting the index property in the field mapping. Setting "index": false means the field is stored but not indexed, so it cannot be searched.

Example parts:

  • "field_name": The name of your field.
  • "type": The data type of the field (e.g., text, keyword, integer).
  • "index": false: Disables indexing, making the field not searchable.
json
{
  "mappings": {
    "properties": {
      "field_name": {
        "type": "text",
        "index": false
      }
    }
  }
}
💻

Example

This example creates an index with a field description that is stored but not searchable because "index": false is set. You can still retrieve the field in search results, but you cannot search by its content.

json
PUT /my_index
{
  "mappings": {
    "properties": {
      "title": {
        "type": "text"
      },
      "description": {
        "type": "text",
        "index": false
      }
    }
  }
}

POST /my_index/_doc/1
{
  "title": "Elasticsearch Guide",
  "description": "This guide explains how to use Elasticsearch."
}

GET /my_index/_search
{
  "query": {
    "match": {
      "description": "guide"
    }
  }
}
Output
{ "hits": { "total": { "value": 0, "relation": "eq" }, "hits": [] } }
⚠️

Common Pitfalls

One common mistake is expecting a field with "index": false to be searchable. Since the field is not indexed, search queries on it will always return no results.

Another pitfall is confusing "index": false with "enabled": false. The latter disables the entire object field, including storage and indexing.

json
/* Wrong: Field is not searchable but query expects results */
GET /my_index/_search
{
  "query": {
    "match": {
      "description": "Elasticsearch"
    }
  }
}

/* Right: Search on a searchable field */
GET /my_index/_search
{
  "query": {
    "match": {
      "title": "Elasticsearch"
    }
  }
}
Output
{ "hits": { "total": { "value": 1, "relation": "eq" }, "hits": [ { "_source": { "title": "Elasticsearch Guide", "description": "This guide explains how to use Elasticsearch." } } ] } }
📊

Quick Reference

  • index: true (default) — Field is searchable.
  • index: false — Field is stored but not searchable.
  • enabled: false — Disables indexing and storage for an object field.
  • Use index: false to exclude fields from search but keep them retrievable.

Key Takeaways

Set "index": false in the field mapping to make a field not searchable.
Fields with "index": false can still be retrieved but not used in search queries.
Do not confuse "index": false with "enabled": false; the latter disables the entire field.
Always test your mappings to confirm fields behave as expected in searches.
Search only works on fields that are indexed (default is true).