Kosi
Kosi

Reputation: 288

Elasticsearch - How does one combine term suggestions from multiple fields?

The term suggester documentation lays out the basics of term suggester, but it leaves me wondering how I can find suggestions from multiple fields and combine them. I can probably come up with some implementation after-the-fact, but I'm wondering if there are some settings I'm missing.

For example, let's say I want to get suggestions from three different fields

GET product-search-product/_search
{
  "suggest": {
    "text": "som typu here",
    "my-suggest-1": {
      "term": {
        "size": 1,
        "max_edits": 1,
        "prefix_length": 3,
        "field": "field_one"
      }
    },
    "my-suggest-2": {
      "term": {
        "size": 1,
        "max_edits": 1,
        "prefix_length": 3,
        "field": "field_two"
      }
    },
    "my-suggest-3": {
      "term": {
        "size": 1,
        "max_edits": 1,
        "prefix_length": 3,
        "field": "field_three"
      }
    }
  }
}

This returns results I can use, but I have to figure out which field had the "best" suggestion.

"suggest": {
"my-suggest-1": [
  {
    "text": "som",
    ...
    "options": [
      {
        "text": "somi"
        ...
      }
    ]
  },
  {
    "text": "typu",
    ...
    "options": [
      {
        "text": "typo"
        ...
      }
    ]
  },
  {
    "text": "here",
    ...
    "options": []
  }
],
"my-suggest-2": [
  {
    "text": "som",
    ...
    "options": [
      {
        "text": "some"
        ...
      }
    ]
  },
  {
    "text": "typu",
    ...
    "options": []
  },
  {
    "text": "here",
    ...
    "options": []
  }
],
"my-suggest-3": [
  {
    "text": "som",
    ...
    "options": []
  },
  {
    "text": "typu",
    ...
    "options": [
      {
        "text": "typa"
        ...
      }
    ]
  },
  {
    "text": "here",
    ...
    "options": []
  }
]

}

It looks to me as if I have to implement something to determine which field came up with the best suggestions. Is there no way to combine these in the suggester so it can do that for me?

Upvotes: 1

Views: 1486

Answers (1)

Kosi
Kosi

Reputation: 288

Phrase suggester was appropriate for my case and with the phrase suggester there exist candidate generators which appear to solve my problem.

Upvotes: 0

Related Questions