# Advise needed to structure data in elasticsearch for search and updates

**URL:** https://discuss.elastic.co/t/advise-needed-to-structure-data-in-elasticsearch-for-search-and-updates/11486
**Category:** Elasticsearch
**Created:** [April 8, 2013, 11:32am UTC](https://discuss.elastic.co/t/advise-needed-to-structure-data-in-elasticsearch-for-search-and-updates/11486 "2013-04-08T11:32:58Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Maaz\_Bin\_Tariq](https://avatars.discourse-cdn.com/v4/letter/m/ee7513/32.png) [@Maaz\_Bin\_Tariq](https://discuss.elastic.co/u/Maaz_Bin_Tariq)
#### Post date: [April 8, 2013, 11:32am UTC](https://discuss.elastic.co/t/advise-needed-to-structure-data-in-elasticsearch-for-search-and-updates/11486/1 "2013-04-08T11:32:58Z")

</div>

Hello,

I have two tables in db (videos and user\_views), now planning to move there  
data to elsticseacrch,

I need an advise how to structure data in elasticsearch for best search and  
analytics.

Following are the type of results, I potentially want to get from  
elasticsearch

1. For Search Query

SELECT a.id, a.video\_title , (SELECT SUM(view\_count) FROM user\_views b  
WHERE b.video\_id = a.id) FROM videos a;  
OR  
SELECT a.\* , (SELECT SUM(view\_count) FROM user\_views b WHERE b.video\_id =  
a.id) FROM videos a;

I can get results by first query videos in elaticssearch and do a term  
stats facet on video id and merge there results.

_What's the best way to get these results from elasticsearch?_  
\*  
\*  
2. For update

UPDATE user\_views SET view\_count = view\_count+1 WHERE user = someUserId;

To update the reusult in elasticsearch

curl -XPOST 'localhost:9200/index/user\_views /1/\_update' -d '{  
"script" : "ctx.\_source.view\_count += count",  
"params" : {  
"count" :1  
}  
}'

_How to put the userId where clause? Is there any other way to update  
records in elasticsearch?_

Kindy suggest

Thanks  
-Maaz

--  
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:42am UTC](https://discuss.elastic.co/t/advise-needed-to-structure-data-in-elasticsearch-for-search-and-updates/11486/2 "2017-07-06T02:42:16Z")

</div>


