Home > Back-end >  Reverse searching with Elastic Search
Reverse searching with Elastic Search

Time:08-02

We have a site and want to give the users the oportunity to save a search query and be notified once an object have been added that would have been a hit they might be interested in.

We Have an index that contains search queries that the users have saved. Every time a new object is added to the object index, we want to do a reverse search in order to find the search queries that would have resulted in a hit for that object. This is in order to avoid doing one search for each saved query every time an object is added.

The problem is that the object contains all data, but the search queries only contain the properties that are interesting. So we are getting zero hits for most queries.

Example:

Search query:

{
  "make": "foo",
  "model": "bar
}

Newly added object:

{
  "make": "foo",
  "model: "bar",
  "type": "jazz"
}

As you can see, the user is interested in any object with make "foo" and model "bar", and we want a query that would result in a hit because type "jazz" is missing in the index. What we get is zero hits.

We use the nest client version 7.13.0 in a dotnet6 application and Elastic Search version 7.13.4.

Would it be possible to reverse search so that a null in the index would be considered as a hit for any search query?

Thank you

CodePudding user response:

You can achieve this with Percolate Query in Elasticsearch.

I have recently written blog on Percolate Query where I have explained with an example.

You can save a user query with Percolate query and when you index document at that time you can call search API and check if any query is matched the document or not. As you are using Nest client this will be easy to implement.

  • Related