Reputation: 482
Let's say I want to store documents like the one below:
{
"item_id": 1,
"item_price": 500,
"currency": "USD"
}
I want the currency field to be like ENUM, so I can predefine the set of values, like: "USD", "GBP", "EUR" and so on...
I also would like that each value will be related to an integer, like hash map, so the set of values will look like this:
{ "USD":1, "GBP":2, "EUR":3 }
how shell I map this field?
Upvotes: 8
Views: 13939
Reputation: 217334
You need to declare your enum in your indexing code and your document should be denormalized like this:
{
"item_id": 1,
"item_price": 500,
"currency": "USD",
"currency_id": 1
}
As for the data types, I suggest to declare the currency
field as keyword
and the currency_id
field as byte
or short
depending on the number of currencies you need to track.
Upvotes: 9