How can I receive completion suggestions with slop?

25 Views Asked by At

I'm trying to search values across multiple fields with certain slop value. For example, I have two text fields with completion suggestion:

######################################
# Prefix completion example
######################################
PUT /prefix-search-001
{
  "mappings": {
    "properties": {
      "first": {
        "type": "text",
        "fields": {
          "completion": {
            "type": "completion"
          }
        }
      },
      "second": {
        "type": "text",
        "fields": {
          "completion": {
            "type": "completion"
          }
        }
      }
    }
  }
}

I put two documents, where there is an ignore word between them:

# ---------------------------------------------------
# Put documents
# ---------------------------------------------------
POST /prefix-search-001/_doc/1
{
  "first": "foo ignore bar",
  "second": "foo ignore baz"
}

POST /prefix-search-001/_doc/2
{
  "first": "foo ignore bar",
  "second": "foo ignore baz"
}

Afterward I'm trying to find both documents by the multimatch query:

###########################################
# Full request
###########################################
GET /prefix-search-001/_search
{
  "size": 2,
  "highlight": {
    "post_tags": [
      "</mark>"
    ],
    "pre_tags": [
      "<mark>"
    ],
    "fields": {
      "first": {},
      "second": {}
    }
  },
  "query": {
    "bool": {
      "should": [
        {
          "multi_match": {
            "_name": "multimatch",
            "query": "foo ba",
            "type": "phrase_prefix",
            "slop": 5,
            "operator": "or",
            "fields": [
              "first",
              "second"
            ]
          }
        }
      ],
      "minimum_should_match": 1
    }
  },
  "suggest": {
    "first-suggestion": {
      "prefix": "foo ba",
      "completion": {
        "field": "first.completion"
      }
    },
    "second-suggestion": {
      "prefix": "foo ba",
      "completion": {
        "field": "second.completion"
      }
    }
  }
}

Is you can see, I've written ba instead of bar or baz.

My query works fine and returns both documents as it should due to preconfigured slop parameter. But I receive no suggestions, because suggestions don't know anything about slop... As far as I've understood from docs all available suggestions work same and do not take into account slop.

Also, I don't think that I can use phrase suggester using shingles, because I can have thousands of words at my document fields and pretty big slop like 200 - 500. It seems that I'll be able only to pollute model with all that shingles...

I expect to see in suggestions including slop:

  1. <mark>foo</mark> ... <mark>bar</mark>
  2. <mark>foo</mark> ... <mark>baz</mark>

Could anyone help me to figure out, how can I achieve this?

0

There are 0 best solutions below