# Complex data query

**URL:** <https://discuss.elastic.co/t/complex-data-query/15904>\
**Category:** Elasticsearch\
**Created:** [February 19, 2014, 6:10pm UTC](https://discuss.elastic.co/t/complex-data-query/15904 "2014-02-19T18:10:22Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Denis\_Uspensky](https://avatars.discourse-cdn.com/v4/letter/d/a6a055/32.png) [@Denis\_Uspensky](https://discuss.elastic.co/u/Denis_Uspensky)\
**Post date:** [February 19, 2014, 6:10pm UTC](https://discuss.elastic.co/t/complex-data-query/15904/1 "2014-02-19T18:10:22Z")

</div>

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](http://google.com) Category1  
10 | [yahoo.com](http://yahoo.com) Category2  
11 | [google.com](http://google.com) Category1  
12 | [yahoo.com](http://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](mailto: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](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](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Binh\_Ly](https://avatars.discourse-cdn.com/v4/letter/b/ce7236/32.png) [@Binh\_Ly](https://discuss.elastic.co/u/Binh_Ly)\
**Post date:** [February 20, 2014, 1:39pm UTC](https://discuss.elastic.co/t/complex-data-query/15904/2 "2014-02-20T13:39:59Z")

</div>

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](mailto: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](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](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 6, 2017, 1:48am UTC](https://discuss.elastic.co/t/complex-data-query/15904/3 "2017-07-06T01:48:40Z")

</div>


