It seems hard to query with relation like SQL in elasticsearch.
I want some recommendation in my case. I have to two indices, user info and user event log.
Here is part of the data:
User Info
+-------+-----------+-----------+
| userId| age | gender |
+-------+-----------+-----------+
| userA | 19 | male |
+-------+-----------+-----------+
| userB | 29 | female |
+-------+-----------+-----------+
| userC | 39 | female |
+-------+-----------+-----------+
User Event log
+---------------------+---------+---------+
| timestamp | action | userId |
+---------------------+---------+---------+
| 2019-10-13 08:34:03 | A | userA |
+---------------------+---------+---------+
| 2019-10-13 11:39:26 | D | userB |
+---------------------+---------+---------+
| 2019-10-14 11:41:23 | A | userA |
+---------------------+---------+---------+
| 2019-10-14 12:10:56 | B | userB |
+---------------------+---------+---------+
| 2019-10-14 12:51:42 | B | userA |
+---------------------+---------+---------+
| 2019-10-14 15:23:48 | C | userA |
+---------------------+---------+---------+
| 2019-10-14 16:05:19 | B | userB |
+---------------------+---------+---------+
| 2019-10-14 19:44:01 | D | userC |
+---------------------+---------+---------+
| 2019-10-15 03:18:15 | D | userA |
+---------------------+---------+---------+
I want to find who doing action D between 2019-10-14 to 2019-10-15 (condition for event log) and gender is male (condition for user info). It should return user A in this case.
I have thought two solution:
The first solution is that get userid by conditions for event log first then using conditions for user info and userid from previous step. Second step query_string example:
gender: male AND ( userId: userB OR userId: userC OR ...)
This solution combines two query result by coding myself. I have some concerns: efficiency and too large query_string if have lot of userids from first step or just maybe get error "out of memory" in server program first.
The second solution is save the event log data in user info and using nest query, but the problem is event log size will be larger and larger. Then the user info document will reach max size limit in a document.
I would appreciate any ideas, thx.