Ability to Search within Results

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.

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?

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

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?

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 ?

Let say your first search is:

{ "match": { "title": "foo" } }

It gives you back 500 docs.

Now, run the following query:

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

It will search bar in the 500 docs.

Is it not what you are asking for?

1 Like

Yes this is exactly I was asking for.

Thanks a lot!

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

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 ?

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.

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

Thanks
Siddharth

Can you tell me what is wrong with that:

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

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

Can you give an exact and concrete script which helps to reproduce your issue?