Completion Suggester with additional conditions in Elastic Search
Asked Answered
S

1

7

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"
          }
        }
      }
    }
}
Stopcock answered 22/10, 2018 at 15:48 Comment(2)
Could you share your mapping details?Hayott
Adding the mapping on the question itselfStopcock
O
6

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.

Openmouthed answered 25/10, 2018 at 7:12 Comment(2)
that is nice, but context using OR and not AND :(Used
Hi, do you know how we can sort results of completion suggestor??Mischance

© 2022 - 2024 — McMap. All rights reserved.