When I store an object as "byte" type in elastic-search it returns it back as a String


(Shankar Vasudevan) #1

The motivation is simple - we have some simple enums like status, commands
etc which we want to index as a single byte rather than a string. In this
example, the mapping looks correct as a byte, but when the object is
indexed, it retrieves as a string in the _source object. Example below

Status

public enum ObjectStatus {

ACTIVE((byte) 'A'), INACTIVE((byte) 'I'), DELETED((byte) 'D');

private final byte value;
private ObjectStatus(byte value) {
   this.value = value;
}

public byte getValue() {
    return value;
}

}

Mapping
{

  • Foo:
    {
    • dynamic: "strict",
    • properties:
      {
      • &a:
        {
        • type: "string",
        • index: "not_analyzed",
        • omit_norms: true,
        • index_options: "docs"
          },
      • &c:
        {
        • type: "string",
        • index: "not_analyzed",
        • omit_norms: true,
        • index_options: "docs"
          },
      • &o:
        {
        • type: "string",
        • index: "not_analyzed",
        • store: true,
        • omit_norms: true,
        • index_options: "docs"
          },
      • &p:
        {
        • type: "binary"
          },
      • &s:
        {
        • type: "byte"
          },
      • &t:
        {
        • type: "date",
        • format: "dateOptionalTime"
          },
      • id:
        {
        • type: "string"
          },
      • name:
        {
        • type: "string"
          }
          }
          }

}

Get on /test-index1/Foo/universal:foos:foo1
{

  • _index: "test-index1",
  • _type: "Foo",
  • _id: "universal:foos:foo1",
  • _version: 1,
  • exists: true,
  • _source:
    {
    • &c: "944fee5b-d4f8-5167-8dd5-3dacfea9f769",
    • id: "universal:foos:foo1",
    • name: "fooyy-universal:foos:foo1",
    • &o: "afd83f34-08da-5c2d-be99-f2a0ec9d358e",
    • &a: "universal:foos:foo1",
    • &s: "65",
    • &p: "l6p0ZXN0UHJpbmNlwMDAwMDA",
    • &t: 1385145687411
      }

}

Can anyone please explain why this behaviour and how to get it back
correctly? Thanks in advance.

Shankar

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


(Ivan Brusic) #2

How are you indexing the enum? Sometimes a different
overloaded XContentBuilder.field() method can be called.

--
Ivan

On Fri, Nov 22, 2013 at 10:51 AM, Shankar Vasudevan <
vasudevan.shankar@gmail.com> wrote:

The motivation is simple - we have some simple enums like status, commands
etc which we want to index as a single byte rather than a string. In this
example, the mapping looks correct as a byte, but when the object is
indexed, it retrieves as a string in the _source object. Example below

Status

public enum ObjectStatus {

ACTIVE((byte) 'A'), INACTIVE((byte) 'I'), DELETED((byte) 'D');

private final byte value;
private ObjectStatus(byte value) {
   this.value = value;
}

public byte getValue() {
    return value;
}

}

Mapping
{

  • Foo:
    {
    • dynamic: "strict",
    • properties:
      {
      • &a:
        {
        • type: "string",
        • index: "not_analyzed",
        • omit_norms: true,
        • index_options: "docs"
          },
      • &c:
        {
        • type: "string",
        • index: "not_analyzed",
        • omit_norms: true,
        • index_options: "docs"
          },
      • &o:
        {
        • type: "string",
        • index: "not_analyzed",
        • store: true,
        • omit_norms: true,
        • index_options: "docs"
          },
      • &p:
        {
        • type: "binary"
          },
      • &s:
        {
        • type: "byte"
          },
      • &t:
        {
        • type: "date",
        • format: "dateOptionalTime"
          },
      • id:
        {
        • type: "string"
          },
      • name:
        {
        • type: "string"
          }
          }
          }

}

Get on /test-index1/Foo/universal:foos:foo1
{

  • _index: "test-index1",
  • _type: "Foo",
  • _id: "universal:foos:foo1",
  • _version: 1,
  • exists: true,
  • _source:
    {
    • &c: "944fee5b-d4f8-5167-8dd5-3dacfea9f769",
    • id: "universal:foos:foo1",
    • name: "fooyy-universal:foos:foo1",
    • &o: "afd83f34-08da-5c2d-be99-f2a0ec9d358e",
    • &a: "universal:foos:foo1",
    • &s: "65",
    • &p: "l6p0ZXN0UHJpbmNlwMDAwMDA",
    • &t: 1385145687411
      }

}

Can anyone please explain why this behaviour and how to get it back
correctly? Thanks in advance.

Shankar

--
You received this message because you are subscribed to the Google Groups
"elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to elasticsearch+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


(Shankar Vasudevan-2) #3

I directly use the Java API and pass in a Map of string/object. I pretty
much guessed that it was default behaviour of Jackson to serialize Byte as
a string. So may be we will need to serialize it before setting the source?

Btw if we use smile format on contentbuilder does anymore serailization
takes place? Sorry I will explain in detail - we currently receive the
objects as a byte[] serialized by msgpack protocol (language independent
clients c# or python) which is deserialized into a map and set as source on
index object. This causes 2 translations one from msgpack to map and from
map to json; the reason we used map was to avoid too much char generation
when the underlying data is predominantly numeric. We were wondering that
if we just did one translation from msgpack to smile (json binary)
directly, we can control the types more strongly. However will that give us
any advantage in terms of indexing time etc?

Thanks again

Shankar

On Friday, 22 November 2013, Ivan Brusic wrote:

How are you indexing the enum? Sometimes a different
overloaded XContentBuilder.field() method can be called.

--
Ivan

On Fri, Nov 22, 2013 at 10:51 AM, Shankar Vasudevan <
vasudevan.shankar@gmail.com <javascript:_e({}, 'cvml',
'vasudevan.shankar@gmail.com');>> wrote:

The motivation is simple - we have some simple enums like status,
commands etc which we want to index as a single byte rather than a string.
In this example, the mapping looks correct as a byte, but when the object
is indexed, it retrieves as a string in the _source object. Example below

Status

public enum ObjectStatus {

ACTIVE((byte) 'A'), INACTIVE((byte) 'I'), DELETED((byte) 'D');

private final byte value;
private ObjectStatus(byte value) {
   this.value = value;
}

public byte getValue() {
    return value;
}

}

Mapping
{

  • Foo:
    {
    • dynamic: "strict",
    • properties:
      {
      • &a:
        {
        • type: "string",
        • index: "not_analyzed",
        • omit_norms: true,
        • index_options: "docs"
          },
      • &c:
        {
        • type: "string",
        • index: "not_analyzed",
        • omit_norms: true,
        • index_options: "docs"
          },

--
You received this message because you are subscribed to the Google Groups
"elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to elasticsearch+unsubscribe@googlegroups.com <javascript:_e({},
'cvml', 'elasticsearch%2Bunsubscribe@googlegroups.com');>.
For more options, visit https://groups.google.com/groups/opt_out.

--
You received this message because you are subscribed to a topic in the
Google Groups "elasticsearch" group.
To unsubscribe from this topic, visit
https://groups.google.com/d/topic/elasticsearch/7dIxazsbtoM/unsubscribe.
To unsubscribe from this group and all its topics, send an email to
elasticsearch+unsubscribe@googlegroups.com <javascript:_e({}, 'cvml',
'elasticsearch%2Bunsubscribe@googlegroups.com');>.
For more options, visit https://groups.google.com/groups/opt_out.

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


(system) #4