# Build document by query

**URL:** <https://discuss.elastic.co/t/build-document-by-query/12055>\
**Category:** Elasticsearch\
**Created:** [May 21, 2013, 1:33pm UTC](https://discuss.elastic.co/t/build-document-by-query/12055 "2013-05-21T13:33:16Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Valentin\_Pletzer](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/valentin_pletzer/32/105548_2.png) [@Valentin\_Pletzer](https://discuss.elastic.co/u/Valentin_Pletzer)\
**Post date:** [May 21, 2013, 1:33pm UTC](https://discuss.elastic.co/t/build-document-by-query/12055/1 "2013-05-21T13:33:16Z")

</div>

Hi,

in order to use the "terms filter" effectively I have to generate a new  
document with the return values of a query. More specifically I would like  
to get a list of ids (not eleasticsearch document ids) and use those ids as  
a terms filter.

Cheers  
Valentin

--  
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:** ![Boaz\_Leskes](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/boaz_leskes/32/723_2.png) [@Boaz\_Leskes](https://discuss.elastic.co/u/Boaz_Leskes)\
**Post date:** [May 22, 2013, 1:10pm UTC](https://discuss.elastic.co/t/build-document-by-query/12055/2 "2013-05-22T13:10:21Z")

</div>

Hi Valentin,

Can you please elaborate? Not sure you are missing.

Cheers,  
Boaz

On Tuesday, May 21, 2013 3:33:16 PM UTC+2, Valentin wrote:

> Hi,
> 
> in order to use the "terms filter" effectively I have to generate a new  
> document with the return values of a query. More specifically I would like  
> to get a list of ids (not eleasticsearch document ids) and use those ids as  
> a terms filter.
> 
> Cheers  
> Valentin

--  
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:** ![Valentin\_Pletzer](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/valentin_pletzer/32/105548_2.png) [@Valentin\_Pletzer](https://discuss.elastic.co/u/Valentin_Pletzer)\
**Post date:** [May 22, 2013, 3:04pm UTC](https://discuss.elastic.co/t/build-document-by-query/12055/3 "2013-05-22T15:04:01Z")

</div>

I use elasticsearch as a storage for a usage logfile. A simple version of  
my documents look like this  
{ timestamp: 231653172, userid: '123', url: '[http://1](http://1)' }  
{ timestamp: 236232844, userid: '456', url: '[http://2](http://2)' }  
...

Now I want to get a list of many userids (eg all userids where url =  
'[http://1](http://1)') and then use this list of userids to get a timeline of all  
pages those users opened.

As I understand it, a new feature of 0.90 is to store those userids in a  
single document in a (secondary) index an then use the ids provided in that  
document to query my primary index.

Cheers,  
Valentin

On Wednesday, May 22, 2013 3:10:21 PM UTC+2, Boaz Leskes wrote:

> Hi Valentin,
> 
> Can you please elaborate? Not sure you are missing.
> 
> Cheers,  
> Boaz
> 
> On Tuesday, May 21, 2013 3:33:16 PM UTC+2, Valentin wrote:
> 
> > Hi,
> > 
> > in order to use the "terms filter" effectively I have to generate a new  
> > document with the return values of a query. More specifically I would like  
> > to get a list of ids (not eleasticsearch document ids) and use those ids as  
> > a terms filter.
> > 
> > Cheers  
> > Valentin

--  
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:** ![Clinton\_Gormley](https://avatars.discourse-cdn.com/v4/letter/c/50afbb/32.png) [@Clinton\_Gormley](https://discuss.elastic.co/u/Clinton_Gormley)\
**Post date:** [May 23, 2013, 10:35am UTC](https://discuss.elastic.co/t/build-document-by-query/12055/4 "2013-05-23T10:35:58Z")

</div>

You'd have to do this in two steps:

1. query to get the ids
2. query using the ids

clint

On 22 May 2013 17:04, Valentin [pletzer@gmail.com](mailto:pletzer@gmail.com) wrote:

> I use elasticsearch as a storage for a usage logfile. A simple version of  
> my documents look like this  
> { timestamp: 231653172, userid: '123', url: '[http://1](http://1)' }  
> { timestamp: 236232844, userid: '456', url: '[http://2](http://2)' }  
> ...
> 
> Now I want to get a list of many userids (eg all userids where url = '  
> [http://1](http://1)') and then use this list of userids to get a timeline of all  
> pages those users opened.
> 
> As I understand it, a new feature of 0.90 is to store those userids in a  
> single document in a (secondary) index an then use the ids provided in that  
> document to query my primary index.
> 
> Cheers,  
> Valentin
> 
> On Wednesday, May 22, 2013 3:10:21 PM UTC+2, Boaz Leskes wrote:
> 
> > Hi Valentin,
> > 
> > Can you please elaborate? Not sure you are missing.
> > 
> > Cheers,  
> > Boaz
> > 
> > On Tuesday, May 21, 2013 3:33:16 PM UTC+2, Valentin wrote:
> > 
> > > Hi,
> > > 
> > > in order to use the "terms filter" effectively I have to generate a new  
> > > document with the return values of a query. More specifically I would like  
> > > to get a list of ids (not eleasticsearch document ids) and use those ids as  
> > > a terms filter.
> > > 
> > > Cheers  
> > > Valentin
> > 
> > --  
> > 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).

--  
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:** ![Valentin\_Pletzer](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/valentin_pletzer/32/105548_2.png) [@Valentin\_Pletzer](https://discuss.elastic.co/u/Valentin_Pletzer)\
**Post date:** [May 24, 2013, 12:32pm UTC](https://discuss.elastic.co/t/build-document-by-query/12055/5 "2013-05-24T12:32:31Z")

</div>

Hi Clint,

thanks I guessed as much. I was hoping for a single query (server side)  
option in order to save one network roundtrip.

Valentin

On Thursday, May 23, 2013 12:35:58 PM UTC+2, Clinton Gormley wrote:

> You'd have to do this in two steps:
> 
> 1. query to get the ids
> 2. query using the ids
> 
> clint
> 
> On 22 May 2013 17:04, Valentin \<[ple...@gmail.com](mailto:ple...@gmail.com) \<javascript:\>\> wrote:
> 
> > I use elasticsearch as a storage for a usage logfile. A simple version of  
> > my documents look like this  
> > { timestamp: 231653172, userid: '123', url: '[http://1](http://1)' }  
> > { timestamp: 236232844, userid: '456', url: '[http://2](http://2)' }  
> > ...
> > 
> > Now I want to get a list of many userids (eg all userids where url = '  
> > [http://1](http://1)') and then use this list of userids to get a timeline of all  
> > pages those users opened.
> > 
> > As I understand it, a new feature of 0.90 is to store those userids in a  
> > single document in a (secondary) index an then use the ids provided in that  
> > document to query my primary index.
> > 
> > Cheers,  
> > Valentin
> > 
> > On Wednesday, May 22, 2013 3:10:21 PM UTC+2, Boaz Leskes wrote:
> > 
> > > Hi Valentin,
> > > 
> > > Can you please elaborate? Not sure you are missing.
> > > 
> > > Cheers,  
> > > Boaz
> > > 
> > > On Tuesday, May 21, 2013 3:33:16 PM UTC+2, Valentin wrote:
> > > 
> > > > Hi,
> > > > 
> > > > in order to use the "terms filter" effectively I have to generate a new  
> > > > document with the return values of a query. More specifically I would like  
> > > > to get a list of ids (not eleasticsearch document ids) and use those ids as  
> > > > a terms filter.
> > > > 
> > > > Cheers  
> > > > Valentin
> > > 
> > > --  
> > > 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 [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> > > For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
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:34am UTC](https://discuss.elastic.co/t/build-document-by-query/12055/6 "2017-07-06T02:34:57Z")

</div>


