4
votes

I am trying to get a simple startswith functionality in Elasticsearch. For example, I want the query "char" to match "charlotte", but I don't want it to match "dacharlotte". Using an edgeNgram filter gave me the latter result. I only want it to match results that START with the query terms, not just have them in them.

1
There is already an answer that can help you, however I am curious about your problem with the edgengram filter. Can you provided the mapping, inserted document and the query?Jettro Coenradie

1 Answers

5
votes

The simplest way to do what you want would be to use the prefix query:

{
    "query": {
         "prefix":{ "name" : "char" }
     }
}

http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-prefix-query.html