Complex data query


(Denis Uspensky) #1

Hello, guys!
I have the following problem. I need to store 2 data structures (tables) in
ES. And there should be parent/child relationship between them. Below is
the index example:

{
"settings": {
"number_of_shards": 1
},
"mappings": {
"testLogs": {
"_source": {
"enabled": false
},
"_parent": {
"type": "testProx"
},
"properties": {
"url": {
"type": "string"
},
"userId": {
"type": "integer"
}
}
},
"testProx": {
"_source": {
"enabled": false
},
"properties": {
"category": {
"type": "string"
}
}
}
}
}

So, as you can see, each record in "testLogs" may have parent record in
"testProx". Imagine, there are some records in "testLogs" with same userId
field. Each record have associated parent record in "testProx":

TestLogs TestProx
================ ==============
UserId | Url Category
================ ==============
10 | google.com Category1
10 | yahoo.com Category2
11 | google.com Category1
12 | yahoo.com Category2

(Category in TestProx is associated with url in TestLogs)

So,i need to find users who have Category1 AND Category2. In example this
is 10 userId ONLY.

Could you please give me an advice , how it can be achieved ? Maybe i
should reorganize the index ?

Thanks

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/72e27d19-5d8b-4cce-b274-ff715d4dcd36%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


(Binh Ly) #2

Maybe try:

/index/testLogs/_search
{
"query": {
"filtered": {
"filter": {
"has_parent": {
"parent_type": "testProx",
"filter": {
"terms": {
"category": [
"category1",
"category2"
]
}
}
}
}
}
}
}

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/8755b41e-6fe2-4bed-8385-d59342ab7e6e%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


(system) #3