higee
higee

Reputation: 377

Elasticsearch mapping parameters : index vs enabled

I've been struggling with two elasticsearch mapping parameters: index and enabled. I'm using Elasticsearch 6.2.4.


Here's my case.

Mapping

PUT my_index
{
  "mappings": {
    "_doc": {
      "properties": {
        "user_id": {
          "type":  "keyword"
        },
        "last_updated": {
          "type": "date"
        },
        "session_data_index_false": { 
          "index" : false,
          "type" : "keyword"
        },
        "session_data_enabled_false": { 
          "enabled" : false
        }
      }
    }
  }
}

Indexing

PUT my_index/_doc/1
{
  "user_id": "jpountz",
  "session_data_index_false": "hello", 
  "session_data_enabled_false": "hello", 
  "last_updated": "2015-12-06T18:22:13"
}

Search1

GET my_index/_search
{
  "query": {
    "match": {
      "session_data_index_false": "hello"
    }
  }
}

I got 400 error with following message.

{
  "error": {
    "root_cause": [
      {
        "type": "query_shard_exception",
        "reason": "failed to create query: {\n  \"match\" : {\n    \"session_data_index_false\" : {\n      \"query\" : \"hello\",\n      \"operator\" : \"OR\",\n      \"prefix_length\" : 0,\n      \"max_expansions\" : 50,\n      \"fuzzy_transpositions\" : true,\n      \"lenient\" : false,\n      \"zero_terms_query\" : \"NONE\",\n      \"auto_generate_synonyms_phrase_query\" : true,\n      \"boost\" : 1.0\n    }\n  }\n}",
        "index_uuid": "6ByxNrjIRQmF23zcmKOvUA",
        "index": "my_index"
      }
    ],
    "type": "search_phase_execution_exception",
    "reason": "all shards failed",
    "phase": "query",
    "grouped": true,
    "failed_shards": [
      {
        "shard": 0,
        "index": "my_index",
        "node": "DYPnEJWjTtm58oxZ9F-RSg",
        "reason": {
          "type": "query_shard_exception",
          "reason": "failed to create query: {\n  \"match\" : {\n    \"session_data_index_false\" : {\n      \"query\" : \"hello\",\n      \"operator\" : \"OR\",\n      \"prefix_length\" : 0,\n      \"max_expansions\" : 50,\n      \"fuzzy_transpositions\" : true,\n      \"lenient\" : false,\n      \"zero_terms_query\" : \"NONE\",\n      \"auto_generate_synonyms_phrase_query\" : true,\n      \"boost\" : 1.0\n    }\n  }\n}",
          "index_uuid": "6ByxNrjIRQmF23zcmKOvUA",
          "index": "my_index",
          "caused_by": {
            "type": "illegal_argument_exception",
            "reason": "Cannot search on field [session_data_index_false] since it is not indexed."
          }
        }
      }
    ]
  },
  "status": 400

Search2

GET my_index/_search
{
  "query": {
    "match": {
      "session_data_enabled_false": "hello"
    }
  }
}

In this case, I didn't get any error. Instead, I got following result, meaning that none of documents was found.

{
  "took": 1,
  "timed_out": false,
  "_shards": {
    "total": 5,
    "successful": 5,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": 0,
    "max_score": null,
    "hits": []
  }
}

Retrieval

GET my_index/_doc/1

Of course, I could retrieve original data.

{
  "_index": "my_index",
  "_type": "_doc",
  "_id": "1",
  "_version": 1,
  "found": true,
  "_source": {
    "user_id": "jpountz",
    "session_data_index_false": "hello",
    "session_data_enabled_false": "hello",
    "last_updated": "2015-12-06T18:22:13"
  }
}

I read official documents on above options.

And also, I've read this article but found out that it was compatible with elasticsearch 1.5.

Is anyone here aware of how those two options differ from each other?

Thanks in advance.

Best

Upvotes: 2

Views: 1995

Answers (1)

Val
Val

Reputation: 217564

When settings enabled to false, you tell ES to completely ignore the parsing of the field, so it will neither be analyzed, nor indexed not stored (except in he _source field of course).

So, ES is not even aware that the field exists, and thus, it handles that case as if you were querying on any other non-existent field, basically as if the source didn't even contain the field. Result: ES doesn't return any document.

When setting index to false, ES is aware that the field exists (via the mapping), but it knows that it shouldn't be indexed. So when you query on it, ES tells you that you cannot do it since you've decided not to index that field. That's why ES throws an error since you're breaking the contract that you've declared in your mapping.

Upvotes: 12

Related Questions