Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Completion Suggester with additional conditions in Elastic Search

I have a index that returns jobs in different languages.

I need to search similar jobs as per a single text that to a single language. So let's say, I have set 1 as LanguageId for English. And I want to search jobs matching with account. So if I write below query, it fetch jobs with all different languages. So basically the "must" query is not having any impact.

GET jobs/_search
{
  "query": {
    "bool": {
      "must": [
        {
          "match": {
            "languageid": "1"
          }
        }
      ]
    }
  },
  "suggest": {
    "suggestions": {
      "text": "acce",
      "completion": {
        "field": "jobs.suggest",
        "size": 30
      }
    }
  }
}

My mapping looks as below

   "mappings": {
"jobs": {
        "properties": {
          "@timestamp": {
            "type": "date"
          },
          "@version": {
            "type": "text"
          },
          "industytype": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          },
          "jobs": {
            "properties": {
              "suggest": {
                "type": "completion",
                "analyzer": "simple",
                "preserve_separators": true,
                "preserve_position_increments": true,
                "max_input_length": 50
              }
            }
          },
          "language": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          },
          "type": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          },
          "updateddate": {
            "type": "date"
          }
        }
      }
    }
}
like image 432
Naibedya Kar Avatar asked Oct 22 '18 15:10

Naibedya Kar


People also ask

How does autocomplete work in Elasticsearch?

Autocomplete can be achieved by changing match queries to prefix queries. While match queries work on token (indexed) to token (search query tokens) match, prefix queries (as their name suggests) match all the tokens starting with search tokens, hence the number of documents (results) matched is high.

What is Elasticsearch suggester?

In the previous articles, we look into Prefix Queries and Edge NGram Tokenizer to generate search-as-you-type suggestions. Suggesters are an advanced solution in Elasticsearch to return similar looking terms based on your text input. Movie, song or job titles have a widely known or popular order.

Did you mean functionality in Elasticsearch?

Elasticsearch is a powerful search engine that offers many benefits, one of which is the Did You Mean feature. This feature helps to correct user queries by automatically suggesting the correct spelling of a word or phrase.

What are analyzed fields in Elasticsearch?

Text field typeedit These fields are analyzed , that is they are passed through an analyzer to convert the string into a list of individual terms before being indexed. The analysis process allows Elasticsearch to search for individual words within each full text field.


1 Answers

There is no way to filter out suggestions at query time, because completion suggester uses FST - special in-memory data structure that built at index time:

Suggesters in Lucene are built in-memory by loading the completion values from the index, then building the FST. This can be a slow, resource intensive process. And, as soon as the index changes, the FST needs to be rebuilt. "Real time search" is a mantra of Elasticsearch. It is not acceptable to return out of date suggestions, nor to require a full rebuild whenever the index changes. Instead of building the FST at search time, we now build an FST per-segment at index time.

So all you can do is to add context for your suggester. Context also filled at index time along with completion field and therefore can be used at query time in suggest query. Also, this article may be useful for you.

like image 144
Alexey Prudnikov Avatar answered Oct 19 '22 03:10

Alexey Prudnikov