Skip_duplicates keeps the lowest-scored document


(Ilia) #1

Hi,

I'm using completion suggester with contexts. Elasticsearch version 6.5.1 from docker hub (official).

Here's the mapping:

PUT /listing_address
{
  "mappings": {
    "listing": {
      "properties": {
        "suggest": {
          "type": "completion",
          "analyzer": "standard",
          "contexts": [
          	{
          		"name": "status_and_rental",
          		"type": "category"
          	}
          ]
        }
      }
    }
  }
}

I have a bunch of documents in the listing_address index:

PUT /listing_address/listing/123123123
{
"suggest": {
    "contexts": {
        "status_and_rental": "U"
    },
    "input": [
        "502-30 Church St, Toronto, ON, M5E1S7",
        "30 Church St Toronto ON M5E1S7"
    ],
    "weight": 662
}
}

PUT /listing_address/listing/123123124
{
"suggest": {
    "contexts": {
        "status_and_rental": "UR"
    },
    "input": [
        "502-30 Church St, Toronto, ON, M5E1S7",
        "30 Church St Toronto ON M5E1S7"
    ],
    "weight": 710
}
}

PUT /listing_address/listing/123123125
{
"suggest": {
    "contexts": {
        "status_and_rental": "U"
    },
    "input": [
        "502-30 Church St, Toronto, ON, M5E1S7",
        "30 Church St Toronto ON M5E1S7"
    ],
    "weight": 1228
}
}

"status_and_rental" context varies from document to document with possible values of "U" or "UR". Weight varies between 662 and 1228.

Here's my search query:

POST /listing_address/_search?pretty
{
  "suggest": {
	 "address-suggest": {
    	"prefix": "502-30 church",
		"completion": {
			"field": "suggest",
			"size": 99,
			"skip_duplicates": true,
			"contexts": {
				"status_and_rental": ["UR", "U"]
			}
		}
      }
  }
}

The query returns one document with the weight of 662. But there are other documents with higher weight. I would expect the document with the highest weight to be returned. What am I doing wrong?