# How to optimize data structure with nested type

**URL:** <https://discuss.elastic.co/t/how-to-optimize-data-structure-with-nested-type/11081>\
**Category:** Elasticsearch\
**Created:** [March 9, 2013, 7:39am UTC](https://discuss.elastic.co/t/how-to-optimize-data-structure-with-nested-type/11081 "2013-03-09T07:39:30Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![zsu\_panda](https://avatars.discourse-cdn.com/v4/letter/z/5e9695/32.png) [@zsu\_panda](https://discuss.elastic.co/u/zsu_panda)\
**Post date:** [March 9, 2013, 7:39am UTC](https://discuss.elastic.co/t/how-to-optimize-data-structure-with-nested-type/11081/1 "2013-03-09T07:39:30Z")

</div>

My ES index and type mapping is as follows:

curl -XPUT '[http://192.168.1.1:9200/linkdb/](http://192.168.1.1:9200/linkdb/)' -d '{  
"settings" : {  
"number\_of\_shards" :20,  
"number\_of\_replicas":1,  
"index.translog.flush\_threshold\_ops": "100000"  
}  
}'

curl -XPUT [http://192.168.1.1:9200/linkdb/FriendLink/\_mapping](http://192.168.1.1:9200/linkdb/FriendLink/_mapping) -d '{  
"FriendLink": {  
"\_source" : { "compress": "true"},  
"\_all" : {"enabled" : "false"},  
"properties": {  
"\_id" : {"type" : "string", "store" : "no"},  
"Tl" : {"index" : "no","type" : "string", "store" : "no"},  
"DM" : {"index" : "not\_analyzed","type" : "string", "store" : "no"},  
"SF" : {"index" : "not\_analyzed","type" : "string", "store" : "no"},  
"Num" : {"index" : "not\_analyzed","type" : "integer", "store" :  
"no"},  
"RK" : {"index" : "not\_analyzed","type" : "integer", "store" : "no"},  
"LK" : {  
"type" : "nested",  
"properties" : {  
"D" : {"index" : "not\_analyzed","type" : "string", "store" : "no"},  
"H" : { "index" : "not\_analyzed","type" : "string" , "store" : "no"},  
"P" : { "index" : "not\_analyzed","type" : "string" , "store" : "no"},  
"T" : {  
"type" : "multi\_field",  
"fields" : {  
"T":{"type" : "string","indexAnalyzer": "standard", "searchAnalyzer":  
"standard", "store" : "no"},  
"UT":{"index" : "not\_analyzed", "type" : "string", "store" : "no"}  
}  
},  
"I" : { "index" : "not\_analyzed", "type" : "boolean", "store" :  
"no" }  
}  
}  
}  
}  
}'

My query is as follows:

curl -XGET '[http://192.168.1.1:9200/linkdb/FriendLink/\_search](http://192.168.1.1:9200/linkdb/FriendLink/_search)?  
pretty=true' -d '{  
from: 0, size: 10,  
fields:["\_id","Tl","Num","RK","LK"],  
"sort":[  
{ "Num" : {"order" : "desc"} }  
],  
"filter" : {  
"nested" : {  
"path" : "LK",  
"query" : {  
"bool" : {  
"must" : [  
{ "term" : { "LK.D" : "[baidu.com](http://baidu.com)" } } ,  
{ "prefix" : { "LK.P" : "/news" } },  
{ "text" : { "LK.T" : "百度" }  
]  
}  
},  
"\_cache" : true  
}  
}

}'

I use nested object type. There are about fifty million documents  
now,each document an average of 30 nested objects.  
It takes an average of a few hundred milliseconds to query once。  
With the growth of the data, the query speed is getting slower and  
slower.  
If the data is more than 100 million documents , I worry about more  
than one second average query.  
For this nested type , I do not know how to optimize my data  
structure.  
Can you help me? Thanks very much.

--  
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).  
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, 2:47am UTC](https://discuss.elastic.co/t/how-to-optimize-data-structure-with-nested-type/11081/2 "2017-07-06T02:47:24Z")

</div>


