Completion Suggester with Exact Starting Match and Whitespace Separated Words

Following the completion suggester example from here: https://www.elastic.co/guide/en/elasticsearch/reference/current/search-suggesters-completion.html

Having trouble understanding how to index titles that have spaces. With the following index/mapping:

curl -XPUT 'localhost:9200/social?pretty' -H 'Content-Type: application/json' -d'
{
    "mappings": {
        "post" : {
            "properties" : {
                "suggest" : {
                    "type" : "completion"
                },
                "title" : {
                    "type": "keyword"
                }
            }
        }
    }
}
'

Adding a suggest with a space like so:

curl -XPOST 'localhost:9200/social/post' -H 'Content-Type: application/json'  '{"suggest":{"input":"Alec Baldwin","weight":4}}'

Produces the following error:

`{"error":{"root_cause":[{"type":"mapper_parsing_exception","reason":"failed to parse"}],"type":"mapper_parsing_exception","reason":"failed to parse","caused_by":{"type":"json_e_o_f_exception","reason":"Unexpected end-of-input in VALUE_STRING\n at [Source: org.elasticsearch.common.bytes.BytesReference$MarkSupportingStreamInputWrapper@691d96c0; line: 1, column: 51]"}},"status":400}curl: (3) [globbing] unmatched close brace/bracket in column 16`

If the space is turned into a dash:

curl -XPOST 'localhost:9200/social/post' -H 'Content-Type: application/json'  '{"suggest":{"input":"Alec-Baldwin","weight":4}}'

The suggest is successfully indexed:

{"_index":"social","_type":"post","_id":"AVtmxoQVIOBiOQZhZa8Y","_version":1,"result":"created","_shards":{"total":2,"successful":1,"failed":0},"created":true}

Have successfully indexed by splitting by space and indexing as an array like {"suggest":{"input":["Alec", "Baldwin"],"weight":4}} however when sending the completion suggester "Ale", this produces other matches like young alec baldwin which is undesired (these are programatically generated, too many to filter out manually); only interested in exact starting matches like Alec Baldwin or Alec Baldwin Jr.

Any insight would be greatly appreciated!

Best,
Joshua

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.