K
K
kolya_krut2017-02-02 19:30:17
elasticsearch
kolya_krut, 2017-02-02 19:30:17

How to properly organize data in an index in Elasticsearch?

Hello.
There is a certain entity with a characteristic that can have an arbitrary number of text values. For example:

"entity1": { "param": ["1", "2", "3"] }
"entity2": { "param": ["1", "2"] }

Search by characteristic values ​​is required (in the case of the example, by "param" values).
Tell me, how best to write data for searching in Elasticsearch? Put each value in ES as a separate entry? Or create some kind of structure? Or else how? Search speed is more important than indexing speed.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vadim Stepanov, 2017-02-09
@Vdm17

If these are just arrays of data, then it is enough to use the standard mapping for the field and the usual queries query term / terms.
Minimal mapping (ES 5.0+)

...
"param": {"type": "keyword"}
...

When filling in data, simply pass an array of values. You don't need to configure anything additionally.
Single Value Search (Sense Query Sample)
GET your_index/your_type/_search
{"query": {"term": {"param": {"value": "2"}}}}

Search by multiple values ​​(sample query for Sense)
GET your_index/your_type/_search
{"query": {"terms": {"param": ["2", "1"]}}}

Approximately like this.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question