哪种模型更适合弹性搜索索引?

时间:2021-03-04 04:15:13

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

我有2个JSON模型,可以表示弹性搜索索引的模型。第一:

{
"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.

实际上,第一个和第二个具有相同的含义并且为弹性搜索索引创建。我认为第一个模型不那么冗余,第二个模型更冗余。但是第一个,表示为1个弹性记录,但第二个表示为2个弹性记录。当我搜索例如ID = 3时,这个东西会产生影响。第一个将返回整个记录,第二个将返回ID = 3的记录。

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

所以,我想要你的所有建议,哪个模型更适合弹性搜索。谢谢...

2 个解决方案

#1


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.

弹性搜索内部没有区别,因为他使用Apache lucene将字段保存为key = value。例如,你第一个例子我将保存为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.

注意:尽可能使用聚合数据,elasticsearch是面向NoSql文档的。

#2


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.

我强烈建议你的第二个模特。 noSQL数据库的一个关键原则是您复制数据以便于查询。

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.

在ES中使用嵌套或父/子是可行的,但它会使您的所有查询更复杂。我们发现扁平化一切都更容易使用,并使我们能够更有效地使用Kibana。

#1


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.

弹性搜索内部没有区别,因为他使用Apache lucene将字段保存为key = value。例如,你第一个例子我将保存为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.

注意:尽可能使用聚合数据,elasticsearch是面向NoSql文档的。

#2


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.

我强烈建议你的第二个模特。 noSQL数据库的一个关键原则是您复制数据以便于查询。

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.

在ES中使用嵌套或父/子是可行的,但它会使您的所有查询更复杂。我们发现扁平化一切都更容易使用,并使我们能够更有效地使用Kibana。