# Ability to Search within Results

**URL:** https://discuss.elastic.co/t/ability-to-search-within-results/29540
**Category:** Elasticsearch
**Created:** [September 18, 2015, 6:07am UTC](https://discuss.elastic.co/t/ability-to-search-within-results/29540 "2015-09-18T06:07:25Z")
**Posts on this page:** 15
**Page:** 1

<div class="post-metadata">

### Author: ![siddharth\_gupta](https://avatars.discourse-cdn.com/v4/letter/s/dec6dc/32.png) [@siddharth\_gupta](https://discuss.elastic.co/u/siddharth_gupta)
#### Post date: [September 18, 2015, 6:07am UTC](https://discuss.elastic.co/t/ability-to-search-within-results/29540/1 "2015-09-18T06:07:25Z")

</div>

Hello,

I wanted to know that is it possible to search within the results that I get through elastic search ?

I was going through the search API & saw this==\>

"It is important to understand that once you get your search results  
back, Elasticsearch is completely done with the request and does not  
maintain any kind of server-side resources or open cursors into your  
results. This is in stark contrast to many other platforms such as SQL  
wherein you may initially get a partial subset of your query results  
up-front and then you have to continuously go back to the server if you  
want to fetch (or page through) the rest of the results using some kind  
of stateful server-side cursor."

Isn't there any way around ?

Thanks  
Siddharth.

---

<div class="post-metadata">

### Author: ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)
#### Post date: [September 18, 2015, 6:28am UTC](https://discuss.elastic.co/t/ability-to-search-within-results/29540/2 "2015-09-18T06:28:59Z")

</div>

Well, there's the scan and scroll feature which is somewhat similar to a SQL result set cursor but I'm not sure what you're trying to accomplish. What does "search within the results" even mean?

---

<div class="post-metadata">

### Author: ![siddharth\_gupta](https://avatars.discourse-cdn.com/v4/letter/s/dec6dc/32.png) [@siddharth\_gupta](https://discuss.elastic.co/u/siddharth_gupta)
#### Post date: [September 18, 2015, 8:33am UTC](https://discuss.elastic.co/t/ability-to-search-within-results/29540/3 "2015-09-18T08:33:23Z")

</div>

Suppose I get 500 hits (for query 'xyz') from my index of 2000 documents.  
Now, I want to search within these 500 hits (and not the complete index) that I got above.  
Did you get my point ?

Thanks  
Siddharth

---

<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: [September 18, 2015, 8:48am UTC](https://discuss.elastic.co/t/ability-to-search-within-results/29540/4 "2015-09-18T08:48:08Z")

</div>

Why running 2 searches?

Just add a filter or wrap your queries in a bool query so you can add more criterias...

The first clause will match your 500 docs, the second one will search within this resultset... Makes sense?

---

<div class="post-metadata">

### Author: ![siddharth\_gupta](https://avatars.discourse-cdn.com/v4/letter/s/dec6dc/32.png) [@siddharth\_gupta](https://discuss.elastic.co/u/siddharth_gupta)
#### Post date: [September 18, 2015, 8:55am UTC](https://discuss.elastic.co/t/ability-to-search-within-results/29540/5 "2015-09-18T08:55:54Z")

</div>

Thanks for the reply!

I want to run 2 searches because:

I want to make it easy for the user to search through the results instead of iterating through them.

Is it possible ?

---

<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: [September 18, 2015, 9:29am UTC](https://discuss.elastic.co/t/ability-to-search-within-results/29540/6 "2015-09-18T09:29:30Z")

</div>

Let say your first search is:

```auto
{ "match": { "title": "foo" } }

```

It gives you back 500 docs.

Now, run the following query:

```auto
{
  "bool": {
    "must": [
      { "match": { "title": "foo" } },
      { "match": { "title": "bar" } }
    ]
  }
}

```

It will search `bar` in the 500 docs.

Is it not what you are asking for?

---

<div class="post-metadata">

### Author: ![siddharth\_gupta](https://avatars.discourse-cdn.com/v4/letter/s/dec6dc/32.png) [@siddharth\_gupta](https://discuss.elastic.co/u/siddharth_gupta)
#### Post date: [September 18, 2015, 10:13am UTC](https://discuss.elastic.co/t/ability-to-search-within-results/29540/7 "2015-09-18T10:13:02Z")

</div>

Yes this is exactly I was asking for.

Thanks a lot!

---

<div class="post-metadata">

### Author: ![siddharth\_gupta](https://avatars.discourse-cdn.com/v4/letter/s/dec6dc/32.png) [@siddharth\_gupta](https://discuss.elastic.co/u/siddharth_gupta)
#### Post date: [September 21, 2015, 3:50am UTC](https://discuss.elastic.co/t/ability-to-search-within-results/29540/8 "2015-09-21T03:50:42Z")

</div>

Hello @dadoonet,

I did try the above solution.  
In the above case we are specific to only one title, however I want that the user should be able to give a query 2nd time.(after getting the results from the first query)

And it should return the results from the search results returned by first query.

Isn't there a way out ?

Thanks  
Siddharth

---

<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: [September 21, 2015, 4:58am UTC](https://discuss.elastic.co/t/ability-to-search-within-results/29540/9 "2015-09-21T04:58:09Z")

</div>

Can you provide a full example of what you have, which query the user run the first time, what is the result and what should happen next ?

---

<div class="post-metadata">

### Author: ![siddharth\_gupta](https://avatars.discourse-cdn.com/v4/letter/s/dec6dc/32.png) [@siddharth\_gupta](https://discuss.elastic.co/u/siddharth_gupta)
#### Post date: [September 21, 2015, 5:53am UTC](https://discuss.elastic.co/t/ability-to-search-within-results/29540/10 "2015-09-21T05:53:39Z")

</div>

Yes.  
So we have an index of 10000 documents related to cancer data for research purposes.  
When I enter the user query 'leukaemia' I get back 1000 related documents as search results.  
Now, what I want is that I should be able to enter another user query, for example 'prevention of leukaemia' and this should search from within the results returned from 'leukaemia' user query.

A simple use case ==\>\>

{Enter user query : leukaemia  
1000 hits  
Enter user query to search from above 1000 hits:  
prevention of leukaemia  
}

Thanks  
Siddharth.

---

<div class="post-metadata">

### Author: ![siddharth\_gupta](https://avatars.discourse-cdn.com/v4/letter/s/dec6dc/32.png) [@siddharth\_gupta](https://discuss.elastic.co/u/siddharth_gupta)
#### Post date: [September 21, 2015, 5:54am UTC](https://discuss.elastic.co/t/ability-to-search-within-results/29540/11 "2015-09-21T05:54:38Z")

</div>

Did you get my point ?  
Is there any way around to resolve this ?

Thanks  
Siddharth

---

<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: [September 21, 2015, 6:16am UTC](https://discuss.elastic.co/t/ability-to-search-within-results/29540/12 "2015-09-21T06:16:12Z")

</div>

Can you tell me what is wrong with that:

```auto
{
  "bool": {
    "must": [
      { "match": { "title": "leukaemia" } },
      { "match": { "title": "prevention of leukaemia" } }
    ]
  }
}

```

---

<div class="post-metadata">

### Author: ![siddharth\_gupta](https://avatars.discourse-cdn.com/v4/letter/s/dec6dc/32.png) [@siddharth\_gupta](https://discuss.elastic.co/u/siddharth_gupta)
#### Post date: [September 21, 2015, 7:22am UTC](https://discuss.elastic.co/t/ability-to-search-within-results/29540/13 "2015-09-21T07:22:25Z")

</div>

This is returning zero hits.  
I do get the results for the first query.

But when when I enter the 2nd query and search using 2 must clauses it is not returning any documents.

Can you please suggest something ?

Thanks  
Siddharth

---

<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: [September 21, 2015, 8:43am UTC](https://discuss.elastic.co/t/ability-to-search-within-results/29540/14 "2015-09-21T08:43:45Z")

</div>

Can you give an [exact and concrete script](https://www.elastic.co/help) which helps to reproduce your issue?

---

<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 5, 2017, 11:49pm UTC](https://discuss.elastic.co/t/ability-to-search-within-results/29540/15 "2017-07-05T23:49:07Z")

</div>


