Tuesday, 16 March 2021

Elasticsearch only one record based on userid?

In post index, postid is primary key and userid is foreign key.

i want all post but only post from one userid, such that only one user have the one post in results sort by postdate(optional latest first)

//Actual Result
[
    {
        userid: "u1",
        postid: "p1"
    },
    {
        userid: "u1",
        postid: "p2"
    },
    {
        userid: "u2",
        postid: "p3"
    },
    {
        userid: "u3",
        postid: "p4"
    },
    {
        userid: "u3",
        postid: "p5"
    },
    {
        userid: "u3",
        postid: "p6"
    }
]

needed as below

//Expecting Result
[
    {
        userid: "u1",
        postid: "p1"
    },
    {
        userid: "u2",
        postid: "p3"
    },
    {
        userid: "u3",
        postid: "p4"
    }
]


from Elasticsearch only one record based on userid?

No comments:

Post a Comment