Hello,

I have an index `facebook` with type `post`. I need to provide users with 
autocompletions using terms that appear in `post.message`. Also the list of 
completions should be sorted by score.

The mapping is as follows:
{
    "post": {
        "properties": {
            "created_time": {
                "type": "date",
                "format": "dateOptionalTime"
            },
            "link": {
                "type": "string"
            },
            "message": {
                "type": "string"
            },
            "object_id": {
                "type": "string"
            },
            "picture": {
                "type": "string"
            },
            "shares_count": {
                "type": "long"
            },
            "type": {
                "type": "string"
            },
            "update_time": {
                "type": "date",
                "format": "dateOptionalTime"
            },
            "user": {
                "type": "long"
            }
        }
    }
}

An example document:
{
    "picture": "...",
    "update_time": "2014-03-19T23:16:59",
    "message": "The
 day has finally arrived - the first piece of the 1,000,000 Swag Bucks 
pie has been served!!  Check to see if you're our first winner!",
    "object_id": "",
    "shares_count": 0,
    "link": "...",
    "user": ...,
    "created_time": "2014-03-17T21:02:32",
    "type": "link"
}

To achieve the goal I've added one more field to the mapping:
"message_suggest": {
    "type": "completion"
}

Every time I write a document, I query ES to tokenize the string `message`:
POST _analyze?_tokenizer=standard
The day has finally arrived - the first piece of the 1,000,000 Swag Bucks 
pie has been served!!  Check to see if you're our first winner!

Then I get the list of tokens from the response and add it to 
`post.message_suggest.input`.

When I do the following request, I get what I wanted:
POST facebook/_suggest
{
    "messages": {
        "text": "pi",
        "completion": {
            "field": "message_suggest"
        }
    }
}

I sense that this approach is not right or at least not optimal. I am new 
to Elasticsearch and I would appreciate any input.

Best,
Sviatoslav.

-- 
You received this message because you are subscribed to the Google Groups 
"elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/elasticsearch/7ea7946c-59e3-4b6b-89f8-0ff327d19017%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to