# Is there a way to return only one result in a query?

**URL:** <https://discuss.elastic.co/t/is-there-a-way-to-return-only-one-result-in-a-query/14953>\
**Category:** Elasticsearch\
**Created:** [December 19, 2013, 2:52pm UTC](https://discuss.elastic.co/t/is-there-a-way-to-return-only-one-result-in-a-query/14953 "2013-12-19T14:52:21Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Adrian\_Luna](https://avatars.discourse-cdn.com/v4/letter/a/258eb7/32.png) [@Adrian\_Luna](https://discuss.elastic.co/u/Adrian_Luna)\
**Post date:** [December 19, 2013, 2:52pm UTC](https://discuss.elastic.co/t/is-there-a-way-to-return-only-one-result-in-a-query/14953/1 "2013-12-19T14:52:21Z")

</div>

I am using the update by query plugin[https://github.com/yakaz/elasticsearch-action-updatebyquery](https://github.com/yakaz/elasticsearch-action-updatebyquery)  
. I only want to update one of the elements that match my query at a  
time and the "size=1" is not working. Is there any other possibility to set  
the number of returned elements to 1.

Thanks for the info.

--  
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/24ed5bec-c3e3-4969-b62d-d6d479aabf53%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/24ed5bec-c3e3-4969-b62d-d6d479aabf53%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:** ![Adrian\_Luna](https://avatars.discourse-cdn.com/v4/letter/a/258eb7/32.png) [@Adrian\_Luna](https://discuss.elastic.co/u/Adrian_Luna)\
**Post date:** [December 20, 2013, 8:45am UTC](https://discuss.elastic.co/t/is-there-a-way-to-return-only-one-result-in-a-query/14953/2 "2013-12-20T08:45:07Z")

</div>

Any clue?

What I actually want is just a "update (table) set (column) where  
(predicate) order by (column) desc limit 1" in sql syntax. Is that possible  
at all in ES???

Thanks!

El jueves, 19 de diciembre de 2013 15:52:21 UTC+1, Adrian Luna escribió:

> I am using the update by query plugin[https://github.com/yakaz/elasticsearch-action-updatebyquery](https://github.com/yakaz/elasticsearch-action-updatebyquery)  
> . I only want to update one of the elements that match my query at a  
> time and the "size=1" is not working. Is there any other possibility to set  
> the number of returned elements to 1.
> 
> Thanks for the info.

--  
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/d7b9cb4f-0129-446d-87a3-38597302644c%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/d7b9cb4f-0129-446d-87a3-38597302644c%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:** ![Adrian\_Luna](https://avatars.discourse-cdn.com/v4/letter/a/258eb7/32.png) [@Adrian\_Luna](https://discuss.elastic.co/u/Adrian_Luna)\
**Post date:** [December 20, 2013, 8:49am UTC](https://discuss.elastic.co/t/is-there-a-way-to-return-only-one-result-in-a-query/14953/3 "2013-12-20T08:49:06Z")

</div>

Any clue?

What I actually want is just a "update () set () where () limit 1" in sql  
syntax.  
If possible, also with an aditional "order by (column) desc".

Is that possible at all in ES???

Thanks!

El jueves, 19 de diciembre de 2013 15:52:21 UTC+1, Adrian Luna escribió:

> I am using the update by query plugin[https://github.com/yakaz/elasticsearch-action-updatebyquery](https://github.com/yakaz/elasticsearch-action-updatebyquery)  
> . I only want to update one of the elements that match my query at a  
> time and the "size=1" is not working. Is there any other possibility to set  
> the number of returned elements to 1.
> 
> Thanks for the info.

--  
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/b18371ed-5112-47e7-ae25-c002c9448156%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/b18371ed-5112-47e7-ae25-c002c9448156%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:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [December 20, 2013, 9:26am UTC](https://discuss.elastic.co/t/is-there-a-way-to-return-only-one-result-in-a-query/14953/4 "2013-12-20T09:26:36Z")

</div>

Why do you want to do this? For test purpose?

--  
David Pilato | Technical Advocate | [Elasticsearch.com](http://Elasticsearch.com)  
@dadoonet | @elasticsearchfr

Le 20 décembre 2013 at 09:49:09, Adrian Luna ([adrian.luna.cobos@gmail.com](mailto:adrian.luna.cobos@gmail.com)) a écrit:

Any clue?

What I actually want is just a "update () set () where () limit 1" in sql syntax.  
If possible, also with an aditional "order by (column) desc".

Is that possible at all in ES???

Thanks!

El jueves, 19 de diciembre de 2013 15:52:21 UTC+1, Adrian Luna escribió:  
I am using the update by query plugin . I only want to update one of the elements that match my query at a time and the "size=1" is not working. Is there any other possibility to set the number of returned elements to 1.

## Thanks for the info.

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/b18371ed-5112-47e7-ae25-c002c9448156%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/b18371ed-5112-47e7-ae25-c002c9448156%40googlegroups.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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/etPan.52b40d4c.580bd78f.111%40MacBook-Air-de-David.local](https://groups.google.com/d/msgid/elasticsearch/etPan.52b40d4c.580bd78f.111%40MacBook-Air-de-David.local).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Adrian\_Luna](https://avatars.discourse-cdn.com/v4/letter/a/258eb7/32.png) [@Adrian\_Luna](https://discuss.elastic.co/u/Adrian_Luna)\
**Post date:** [December 20, 2013, 9:57am UTC](https://discuss.elastic.co/t/is-there-a-way-to-return-only-one-result-in-a-query/14953/5 "2013-12-20T09:57:43Z")

</div>

I want to have several processes reindexing documents with updated  
information if it isn't already updated/being updated by other process.  
Thus, with the query I'll check a flag, and update its state to processing  
(atomic operation). The next process will come up and select a still  
non-processed document, since the flag is updated.

I guess if the plugin allows to do this for the complete set of matched  
documents, it should be possible to do it for just 1 doc.

Thanks in advance.

El viernes, 20 de diciembre de 2013 10:26:36 UTC+1, David Pilato escribió:

> Why do you want to do this? For test purpose?
> 
> --  
> _David Pilato_ | _Technical Advocate_ | _[Elasticsearch.com](http://Elasticsearch.com)_  
> @dadoonet [https://twitter.com/dadoonet](https://twitter.com/dadoonet) | @elasticsearchfr[https://twitter.com/elasticsearchfr](https://twitter.com/elasticsearchfr)
> 
> Le 20 décembre 2013 at 09:49:09, Adrian Luna ([adrian.l...@gmail.com](mailto:adrian.l...@gmail.com)\<javascript:\>)  
> a écrit:
> 
> Any clue?
> 
> What I actually want is just a "update () set () where () limit 1" in sql  
> syntax.  
> If possible, also with an aditional "order by (column) desc".
> 
> Is that possible at all in ES???
> 
> Thanks!
> 
> El jueves, 19 de diciembre de 2013 15:52:21 UTC+1, Adrian Luna escribió:
> 
> > I am using the update by query plugin[https://github.com/yakaz/elasticsearch-action-updatebyquery](https://github.com/yakaz/elasticsearch-action-updatebyquery)  
> > . I only want to update one of the elements that match my query at a  
> > time and the "size=1" is not working. Is there any other possibility to set  
> > the number of returned elements to 1.
> > 
> > Thanks for the info.
> 
> --  
> 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:\>.  
> To view this discussion on the web visit  
> [https://groups.google.com/d/msgid/elasticsearch/b18371ed-5112-47e7-ae25-c002c9448156%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/b18371ed-5112-47e7-ae25-c002c9448156%40googlegroups.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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/a8221681-276b-49ec-bf03-e26c93c042b1%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/a8221681-276b-49ec-bf03-e26c93c042b1%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/is-there-a-way-to-return-only-one-result-in-a-query/14953/6 "2017-07-06T02:00:00Z")

</div>


