Search code examples
elasticsearch

ElasticSearch: how to get a field other field than object, with enabled set to False?


I want to create a mapping where one of the field are bytes (in fact, arrays or arrays of bytes). I don't need to do searches on this field, and therefore I want to defined it with "enabled":False. Also, I want it to defined it has byte to save space. However, if I use the following:

"colbert_b":{"type":"byte","enabled":False}

I get the error:

BadRequestError: BadRequestError(400, 'mapper_parsing_exception', 'unknown parameter [enabled] on mapper [colbert_b] of type [byte]')

Solution

  • Below is what mentioned in this documentation. that means you cant use "enabled":False for the byte type of field.

    The enabled setting, which can be applied only to the top-level mapping definition and to object fields, causes Elasticsearch to skip parsing of the contents of the field entirely.

    You can use doc_values parameter and set it values to the false. this will disabled the search, sort, aggregation and scripting on field but you will be still able to retrieve field in response.

    PUT my-index-000001
    {
      "mappings": {
        "properties": {
          "colbert_b": { 
            "type": "byte",
            "doc_values": false,
            "index": false
          }
        }
      }
    }