To return the query results in the order you want, execute the sort on a 
not_analyzed version of the term, i.e

"DISPLAY_NAME": {
    "type": "string",
    "fields": {
         "NAME": {
              "type": "string",
             "analyzer": "edge_ngram_keyword_lowercase_analyzer"
        },
        "untouched":{
             "type": "string",
                  "analyzer":"not_analyzed"
              }
        }
}

Reindex the data. Now in your query you can sort on the 'untouched' field:

{
    "from" : "0",
    "size" : "20",
    "explain" : true,
   
    "query" : {
    "multi_match": {
         "query": "happy",
          "fields": [ "DISPLAY_NAME.name"]
     }
    },
    "sort" : [{ 
      "DISPLAY_NAME.untouched" : { "order" : "desc"}}] 
}

which will return 

*1)Happy*
*2)Happy birthday*
*3)Happy valentine*

Dan


On Monday, April 28, 2014 9:50:44 AM UTC+1, cyrilforce wrote:
>
> Hi All, 
>
> I am trying to use *edge-ngram filter *to achieve auto-completion 
> behaviour. However when i run the following query : 
>
> {
>     "from" : "0",
>     "size" : "20",
>     "explain" : true,
>    
>     "query" : {
>     *"multi_match": {*
> *      "query": "happy",*
> *      "fields": [ "DISPLAY_NAME.NAME <http://DISPLAY_NAME.NAME>"]*
> *     }*
>     },
>     "sort" : [{ 
>       "_score" : { "order" : "desc"}}] 
> }
>
> It returns me documents  : 
>
> https://gist.github.com/cheehoo/11365794
>
>
> May i know how can i achieve the behaviour when i search "*happy*" then 
> is should return me following result instead : 
>
> *1)Happy*
> *2)Happy birthday*
> *3)Happy valentine*
>
>
> The analzyer configure : 
>
> "analysis" : {
> "analyzer" : {
> "edge_ngram_keyword_lowercase_analyzer" : {
> "tokenizer" : "keyword",
> "filter" : ["my_edge_ngram_filter","lowercase"]
> }
> },
>  "filter" : {
>                     "my_edge_ngram_filter" : {
>                         "type" : "edgeNGram",
>                         "min_gram" : "2",
>                         "max_gram" : "30"
>                         
>                     }
>                 }
>  }
>
>
> The mapping :
> https://gist.github.com/cheehoo/11365917
>
> Thanks.
>
>
>
>
>
>

-- 
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/7ad16d4e-aed3-474e-893d-92cc788003b0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to