New

The executive guide to generative AI

Read more
IMPORTANT: This documentation is no longer updated. Refer to Elastic's version policy and the latest documentation.

Binary field type

edit

The binary type accepts a binary value as a Base64 encoded string. The field is not stored by default and is not searchable:

resp = client.indices.create(
    index="my-index-000001",
    mappings={
        "properties": {
            "name": {
                "type": "text"
            },
            "blob": {
                "type": "binary"
            }
        }
    },
)
print(resp)

resp1 = client.index(
    index="my-index-000001",
    id="1",
    document={
        "name": "Some binary blob",
        "blob": "U29tZSBiaW5hcnkgYmxvYg=="
    },
)
print(resp1)
response = client.indices.create(
  index: 'my-index-000001',
  body: {
    mappings: {
      properties: {
        name: {
          type: 'text'
        },
        blob: {
          type: 'binary'
        }
      }
    }
  }
)
puts response

response = client.index(
  index: 'my-index-000001',
  id: 1,
  body: {
    name: 'Some binary blob',
    blob: 'U29tZSBiaW5hcnkgYmxvYg=='
  }
)
puts response
const response = await client.indices.create({
  index: "my-index-000001",
  mappings: {
    properties: {
      name: {
        type: "text",
      },
      blob: {
        type: "binary",
      },
    },
  },
});
console.log(response);

const response1 = await client.index({
  index: "my-index-000001",
  id: 1,
  document: {
    name: "Some binary blob",
    blob: "U29tZSBiaW5hcnkgYmxvYg==",
  },
});
console.log(response1);
PUT my-index-000001
{
  "mappings": {
    "properties": {
      "name": {
        "type": "text"
      },
      "blob": {
        "type": "binary"
      }
    }
  }
}

PUT my-index-000001/_doc/1
{
  "name": "Some binary blob",
  "blob": "U29tZSBiaW5hcnkgYmxvYg==" 
}

The Base64 encoded binary value must not have embedded newlines \n.

Parameters for binary fields

edit

The following parameters are accepted by binary fields:

doc_values

Should the field be stored on disk in a column-stride fashion, so that it can later be used for sorting, aggregations, or scripting? Accepts true or false (default). This parameter will be automatically set to true for TSDB indices (indices that have index.mode set to time_series).

store

Whether the field value should be stored and retrievable separately from the _source field. Accepts true or false (default).

Synthetic _source

edit

Synthetic source may sort binary values in order of their byte representation. For example:

response = client.indices.create(
  index: 'idx',
  body: {
    mappings: {
      _source: {
        mode: 'synthetic'
      },
      properties: {
        binary: {
          type: 'binary',
          doc_values: true
        }
      }
    }
  }
)
puts response

response = client.index(
  index: 'idx',
  id: 1,
  body: {
    binary: [
      'IAA=',
      'EAA='
    ]
  }
)
puts response
PUT idx
{
  "mappings": {
    "_source": { "mode": "synthetic" },
    "properties": {
      "binary": { "type": "binary", "doc_values": true }
    }
  }
}
PUT idx/_doc/1
{
  "binary": ["IAA=", "EAA="]
}

Will become:

{
  "binary": ["EAA=", "IAA="]
}
Was this helpful?
Feedback