# What would be the best data structure for efficient search on this data?

**URL:** https://discuss.elastic.co/t/what-would-be-the-best-data-structure-for-efficient-search-on-this-data/18132
**Category:** Elasticsearch
**Created:** [June 16, 2014, 12:26pm UTC](https://discuss.elastic.co/t/what-would-be-the-best-data-structure-for-efficient-search-on-this-data/18132 "2014-06-16T12:26:18Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Beetel](https://avatars.discourse-cdn.com/v4/letter/b/b3f665/32.png) [@Beetel](https://discuss.elastic.co/u/Beetel)
#### Post date: [June 16, 2014, 12:26pm UTC](https://discuss.elastic.co/t/what-would-be-the-best-data-structure-for-efficient-search-on-this-data/18132/1 "2014-06-16T12:26:18Z")

</div>

I am using elasticsearch 1.2.0.

I have around 3 million documents which can be of 2 types - 'products' or  
'categories'. Currently I am usingscript filters  
[http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-script-filter.html](http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-script-filter.html) to  
check whether category\_name1 exists in 'belongs\_to\_categories' array.

I have to reindex the data, so I have the opportunity to modify the  
structure of the data. Any ideas how should I structure my data so that  
search based on 'belongs to this category' are fastest?

My data is currently in the form -

"\_type": "product",  
"\_source": {  
"id": "id1",  
...,  
"name": "product\_name",  
"belongs\_to\_categories": [category\_name1, category\_name2]  
}

"\_type": "category",  
"\_source": {  
"id": "1ID",  
"name": "category\_name1"  
...  
}

--  
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/745afc0b-7629-4845-afbe-173bffeb0842%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/745afc0b-7629-4845-afbe-173bffeb0842%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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:22am UTC](https://discuss.elastic.co/t/what-would-be-the-best-data-structure-for-efficient-search-on-this-data/18132/2 "2017-07-06T01:22:12Z")

</div>


