A
A
Artyom2018-09-10 00:46:16
elasticsearch
Artyom, 2018-09-10 00:46:16

ElasticSearch: how to search nested structures correctly?

The elastic index stores nested data structures for which you want to perform a correct search.
Index example:

{
    "title": {"type": "text"},
    "subEntity": {
        "type": "object",
        "properties": {
            "id": {"type": "integer"},
            "value": {"type": "text"}
        }
    }
}

Sample data:
{
    "title": "Stub",
    "subEntity": [
        {"id": 1, "value": "red"},
        {"id": 2, "value": "yellow"},
        {"id": 3, "value": "green"}
    ]
}

Request example:
{
    "query": {
        "bool": {
            "must": [
                {"match": {"subEntity.id": 1}},
                {"match": {"subEntity.value": "yellow"}}
            ]
        }
    }
}

Naturally, the search will be carried out not at the level of the same nested structure (subEntity), but on all nested structures within the same record, and the above example will be found by the request described.
Is it possible somehow, without rebuilding the index, to organize the query so that the search is performed within each nested structure, and not the record as a whole?
If, for a correct search by subEntity, they still have to be moved to a separate index, is it possible to get parent records in one query?
ES version: 6.4

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Ernest Faizullin, 2018-09-10
@dexes56

you need to look in Google for the query "elastic search handle relations"
for example https://www.elastic.co/guide/en/elasticsearch/guid...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question