Elasticsearch: save redundant (denormalized) data or keep a list of identifiers for cross-references?

Is it better to store redundant data in an index or have two indexes and then cross-reference them? those. the user wants to watch movies in the theater.

Since the user is interested in finding films in the theater, we can have a theater index with nested_type films:

// Here, movies field will be a Nested Type, not Object Type.

eclient.index({
    index: 'myindex',
    type: 'theater',
    id: 1,
    body: {
        name: "Grand Cinema",
        description: "Come watch movies!",
        movies: [
           {
               title: "Red November",
               description: "A submarine hunt",
               rated: "R",
               score: 10.0
           },
           {
               title: "Cinderbrella",
               description: "A burnt umbrella",
               rated: "PG",
               score: 8.8
           }
        ]

    }
});

This makes it easy to display a short list of films on the theater, as the data is denormalized in the theater.

We may also have a movie index, which contains more information about the movie:

eclient.index({
    index: 'myindex',
    type: 'movie',
    id: 1,
    body: {
        title: "Red November",
        description: "A submarine hunt",
        rated: "R",
        score: 10.0,
        actors: ["Bob", "Alice", "Carol"],
        // other details...
    }
});

So, when a user clicks on a movie to get more information, I can query the movie index and get its detailed information (i.e., the actors).

, . , . : . .. .

, , , :

// theater index
type: 'theater',
id: 1,
body: {
    name: ...
    description: ...
    movies: [ 1, 2 ]
}

// movie index
type: 'movie',
id: 1,
body: {
    title: ...
    description: ...
    theaters: [ 1, 2, 3]
}

, ? , , . , , .

? , , , , , ( ?).

, , Postgres . , , , ?

+4

Source: https://habr.com/ru/post/1570747/


All Articles