Dynamic field type


(Herbert Bodner) #1

Hi,

I have the following (simplified) structure:

{
"id": "571344ad-c234-4144-92c2-94efa991240c",
"name": "MyDocument.pdf",
"metaDataValueLst": [
{
"metaDataFieldID": "19a2c920-013c-4a9f-91c7-d1a16a168779",
"metaDataFieldName": "BillNr",
"metaDataValue": 5514
},
{
"metaDataFieldID": "83d65910-70d5-4a97-9bfb-b21a6270e55c",
"metaDataFieldName": "BillDate",
"metaDataValue": "2012-08-30T22:49:00.927",
},
{
"metaDataFieldID": "bdf56521-cd9c-47f5-a8c7-bc344c57e1f7",
"metaDataFieldName": "Description",
"metaDataValue": "The description"
}
]
}

As you can see, the field "metaDataValueLst.metaDataValue" can contain
values of different types (numeric, datetime or string).
I could just use the type "string" for the metaDataValue field, but then I
would not be able to apply range-searches...
Is it possible to create a corresponding mapping in a way, that the value
is indexed according to its specific type?

I think creating a Multifield with 3 fields (metaDataValue_string,
metaDataValue_numeric, metaDataValue_date) would solve the problem, but
this would increase the search complexity and require additional space.
Any better suggestions?

--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/5379f52c-62b7-4a6c-b025-06b8a176e14a%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


(Alexander Reelsen) #2

Hey,

Multifields are not the way to go here, as it basically indexes one field
(like metaDataValue) into several fields in your indices.

depending on your type of search, you just need to configure your mapping
appropriately or you may need nested documents. The simple solution is to
make use of the object type in your mapping
http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/mapping-object-type.html

This basically works, but as soon as you need to query for
metaDataValueLst.id and metaDataValueLst.value in one query, you will need
nested documents to make this work, as by default all field values form the
nested objects are flattened into one array before being indexed. (Hope
this makes sense with that short explanation).

Hope this helps as a start.

--Alex

On Sat, Jan 25, 2014 at 6:55 PM, Herbert Bodner herbert.bodner@gmail.comwrote:

Hi,

I have the following (simplified) structure:

{
"id": "571344ad-c234-4144-92c2-94efa991240c",
"name": "MyDocument.pdf",
"metaDataValueLst": [
{
"metaDataFieldID": "19a2c920-013c-4a9f-91c7-d1a16a168779",
"metaDataFieldName": "BillNr",
"metaDataValue": 5514
},
{
"metaDataFieldID": "83d65910-70d5-4a97-9bfb-b21a6270e55c",
"metaDataFieldName": "BillDate",
"metaDataValue": "2012-08-30T22:49:00.927",
},
{
"metaDataFieldID": "bdf56521-cd9c-47f5-a8c7-bc344c57e1f7",
"metaDataFieldName": "Description",
"metaDataValue": "The description"
}
]
}

As you can see, the field "metaDataValueLst.metaDataValue" can contain
values of different types (numeric, datetime or string).
I could just use the type "string" for the metaDataValue field, but then
I would not be able to apply range-searches...
Is it possible to create a corresponding mapping in a way, that the value
is indexed according to its specific type?

I think creating a Multifield with 3 fields (metaDataValue_string,
metaDataValue_numeric, metaDataValue_date) would solve the problem, but
this would increase the search complexity and require additional space.
Any better suggestions?

--
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.
To view this discussion on the web visit
https://groups.google.com/d/msgid/elasticsearch/5379f52c-62b7-4a6c-b025-06b8a176e14a%40googlegroups.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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/CAGCwEM98ceBtvrQGFYupC%2BvYyYhBRwrJVpeFGb7%2B46QRgxNyhA%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.


(Jörg Prante) #3

Concise version, single mapping:

_index "test"
_type "bills"
_id "571344ad-c234-4144-92c2-94efa991240c"
{
"name": "MyDocument.pdf",
"relations" : [
{
"id" : "19a2c920-013c-4a9f-91c7-d1a16a168779",
"BillNr": 5514
},
{
"id" : "83d65910-70d5-4a97-9bfb-b21a6270e55c",
"BillDate": "2012-08-30T22:49:00.927"
},
{
"id" : "bdf56521-cd9c-47f5-a8c7-bc344c57e1f7",
"Description":"The description"
}
]
}

With multiple mappings:

_index "test"
_type "docs"
_id "571344ad-c234-4144-92c2-94efa991240c"
{
"name": "MyDocument.pdf",
"relations" : [
"19a2c920-013c-4a9f-91c7-d1a16a168779",
"83d65910-70d5-4a97-9bfb-b21a6270e55c",
"bdf56521-cd9c-47f5-a8c7-bc344c57e1f7"
]
}

_index "test"
_type" "billnumbers"
_id "19a2c920-013c-4a9f-91c7-d1a16a168779"
{
"BillNr": 5514
}

_index "test"
_type "billdates"
_id "83d65910-70d5-4a97-9bfb-b21a6270e55c"
{
"BillDate": "2012-08-30T22:49:00.927"
}

_index "test"
_type "descriptions"
_id "bdf56521-cd9c-47f5-a8c7-bc344c57e1f7"
{
"Description":"The description"
}

Using many documents, you also have the option for parent/child. It depends
how complex the children docs are. Only one field, as shown here, is a bad
example.

Jörg

--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/CAKdsXoFoXY%3D4Kg%2Bi9w8cS3PH8Lj9HvtViXjwZ%2BSg5e53AiEzTQ%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.


(system) #4