B
B
bio2016-12-19 14:40:26
elasticsearch
bio, 2016-12-19 14:40:26

What is the correct way to store documents in Elasticsearch?

Hello!
I can't figure out how to properly store and update data.
There are several objects related to each other, for example:
Clients objects

{
    id: 1,
    name: 'client 1',
    tags: [
        {
            id: 1,
            name: 'tag 1'
        },
        {
            id: 2,
            name: 'tag 2'
        }
    ],
    deals: [
        {
            id: 1,
            name: 'deal 1',
            tags: [
                {
                    id: 1,
                    name: 'tag 1'
                }
            ]
        }
    ]
}

Deal Objects
[
    {
        id: 1,
        name: 'deal 1',
        tags: [
            {
                id: 1,
                name: 'tag 1'
            }
        ]
    },
    {
        id: 2,
        name: 'deal 2',
        tags: [
            {
                id: 2,
                name: 'tag 2'
            }
        ]
    }
]

Object Tags
[
    {
        id: 1,
        name: 'tag 1'
    },
    {
        id: 2,
        name: 'tag 2'
    }
]

This is data in a denormalized form, as I understand it, that's how they send it to elastic.
Is it worth it to keep it this way?
How flexible can you configure search and filtering?
How to update nested objects if the original changes? For example, in the tag object with id = 1, the name field has changed to 'tag 3'. Is it possible to find and change this object in other objects using the elastic force?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Max, 2016-12-19
@MaxDukov

I won’t comment on the first part, but something tells me that you shouldn’t pull logic from SQL into NoSQL.
on update - yes, you can update and not add a record, you need to make a unique field in the index. it can be any field - if the value in this field matches the "inserted" and the existing record, the existing one will be updated.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question