Make pharse prefix search on whole text of a field


(JavaES) #1

Hi I am using the match phrase prefix query

{
"match" : {
"suggestion" : {
"query" : "lub*",
"type" : "phrase_prefix",
}
}
}

With this query m getting results as

{
"name": "lube it all"
},
{
"name": "assembly lubricant"
}

I don't want assembly lubricant in the search result as it starts with assembly word,
I want the ES to check with whole word's prefix instead of terms ,is there any way to sort this out,wild card query also giving the same result,


(Nik Everett) #2

Do a prefix query against that field analyzed with the keyword tokenizer.
Or do a term query against it analyzed with the edge ngram tokenizer.


(JavaES) #3

Thanks Nik.i will change the mapping's and will add the analyzer


(JavaES) #4

Hi Nik,
Analyzer : settings

               "analyzer": {
                  "didYouMean": {
                     "type": "custom",
                     "char_filter": [
                        "html_strip"
                     ],
                     "filter": [
                        "lowercase"
                     ],
                     "tokenizer": "standard"
                  },
                  "default": {
                     "type": "custom",
                     "char_filter": [
                        "html_strip"
                     ],
                     "filter": [
                        "lowercase",
                        "stopwords",
                        "stemmer"
                     ],
                     "tokenizer": "standard"
                  },
                  "autocomplete": {
                     "type": "custom",
                     "char_filter": [
                        "html_strip"
                     ],
                     "filter": [
                        "lowercase",
                        "autocompleteFilter"
                     ],
                     "tokenizer": "standard"
                  },
                  **"keylower": {**
**                     "filter": "lowercase",**
**                     "tokenizer": "keyword"**
**                  }**
               }

Mapping:

    **"suggestion": {**
**                  "type": "string",**
**                  "copy_to": [**
**                     "did_you_mean",**
**                     "autocomplete",**
**                     "keylower"**
**                  ]**
**               }**

M using this query

{
  "prefix" : {
    "suggestion" : {
      "prefix" : "lub"
    }
  }
}

Still m getting the unwanted result :confused:

                    "name": "air lube"
                },
                {
                    "name": "lubricant"

M I missing something?,is my analyzer defination is correct?,please make me correct if I am wrong.


(Nik Everett) #5

I'm not sure! It'd be easier to figure out with the full results instead of snippets but I think this is happening because you have object fields but you want to have nested subfields? I'm not 100% sure.


(system) #6