问题
Need help constructing an ES query. Here's an example of the raw JSON of the documents:
{
"user_uuid": 1234,
"keywords": "apple",
"@timestamp": "2020-01-15",
},
{
"uuid": 1234,
"keywords": "google",
"@timestamp": "2020-01-21",
},
{
"uuid": 9876,
"keywords": "youtube",
"@timestamp": "2020-01-25",
}
Here is an example requirement:
{
"search_groups":[
{
"keywords": [
"google",
"microsoft",
"tesla"
],
"time_range": 2020-01-17 - 2020-01-22
},
{
"keywords": [
"apple",
"youtube",
"spotify"
],
"time_range": 2020-01-10 - 2020-01-25
},
]
}
Here is what I want to achieve based on the above requirement:
I should be able to get the unique user_uuid which satisfies all the search groups. That is,
Get unique uuids where both conditions are true:
(
(keywords should match one of "google" OR "microsoft" OR "tesla")
and
(@timestamp must be between "2020-01-17" and "2020-01-22")
)
AND
(
(keywords should match one of "apple" OR "youtube" OR "spotify")
and
(@timestamp must be between "2020-01-10" and "2020-01-25")
)
1234 is the user_uuid which satisfies this query.
How do I construct this as an ES query?
来源:https://stackoverflow.com/questions/59949450/how-to-write-an-elasticsearch-query-having-multiple-conditions