0

I have 2 JSON model that can represented model for elasticsearch indexing. First :

{
"id" : 1,
"nama" : "satu", 
"child" : {
    "id" : 2,
    "nama" : "dua",
    "child" : [
        {
            "id" : 3
            "nama" : "tiga"
        },
        {
            "id" : 4,
            "nama" : "empat"
        }
    }
}

}

And second :

[{
    "parent1id" : 1,
    "parent1nama" : "satu",
    "parent2id" : 2,
    "parent2nama" : "dua",
    "id" : 3,
    "nama" : "tiga"
},
{
    "parent1id" : 1,
    "parent1nama" : "satu",
    "parent2id" : 2,
    "parent2nama" : "dua",
    "id" : 4,
    "nama" : "empat"
}]

Actually both first and second have the same meaning and created for elasticsearch indexing. I think the first model is less redundant, and the second ones is more redundant. But the first ones, represented as 1 elastic record, but the second ones represented as 2 elastic record. This thing will impact when I do searching for example ID = 3. The first ones, will return the whole record, and the second ones will return the record that the ID = 3.

So, I want your suggestion all, which model better for elasticsearch. Thanks...

2 Answers 2

1

There's no diference inside elasticsearch because he uses Apache lucene to save your fields as key = value. for example you first example i'll be save as child.id = 3, child.mama = tiga.

But a good point in your first case the child object will be indexed as Nested Object that have a lot of possibilities as filters, queries and another kind of things. Take a look in nested object i think this will clarify your needs.

Note: use aggregated data when is possible, elasticsearch is a NoSql document oriented.

0

I strongly suggest your 2nd model. A key principal of a noSQL database is that you duplicate data to make it easier to query.

Using Nested or Parent/Child in ES is doable, but it makes all your queries more complicated. We have found that flattening everything is much easier to work with and allows us to use Kibana much more efficiently.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.