# How to obtain document fields during query rewrite

**URL:** <https://discuss.elastic.co/t/how-to-obtain-document-fields-during-query-rewrite/14897>\
**Category:** Elasticsearch\
**Created:** [December 16, 2013, 10:43pm UTC](https://discuss.elastic.co/t/how-to-obtain-document-fields-during-query-rewrite/14897 "2013-12-16T22:43:34Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ricky\_Nguyen](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ricky_nguyen/32/1907_2.png) [@Ricky\_Nguyen](https://discuss.elastic.co/u/Ricky_Nguyen)\
**Post date:** [December 16, 2013, 10:43pm UTC](https://discuss.elastic.co/t/how-to-obtain-document-fields-during-query-rewrite/14897/1 "2013-12-16T22:43:34Z")

</div>

I'd like to create a plugin with a custom Query that looks something like  
this:

{ my\_query: { id: "52952683291b6d43120de872" } }

And in the rewrite method, I'd like to use values from that document. For  
example, if the document looks like:

{ \_id: "52952683291b6d43120de872", foo: 23, bar: 103 }

Then I may want to rewrite my\_query as:

{ numeric\_range: { foobar: { gte: 23, lte: 103 } } }

In my rewrite method implementation, how do I obtain the reference document?

Thanks,  
Ricky

--  
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/5f5b25fb-64f6-49a0-978d-b61b93f9c4e0%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/5f5b25fb-64f6-49a0-978d-b61b93f9c4e0%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, 2:00am UTC](https://discuss.elastic.co/t/how-to-obtain-document-fields-during-query-rewrite/14897/2 "2017-07-06T02:00:49Z")

</div>

Closed on July 6, 2017, 2:00am UTC


