# Make pharse prefix search on whole text of a field

**URL:** <https://discuss.elastic.co/t/make-pharse-prefix-search-on-whole-text-of-a-field/62263>\
**Category:** Elasticsearch\
**Created:** [October 5, 2016, 11:29am UTC](https://discuss.elastic.co/t/make-pharse-prefix-search-on-whole-text-of-a-field/62263 "2016-10-05T11:29:35Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![prasad\_kp](https://avatars.discourse-cdn.com/v4/letter/p/dc4da7/32.png) [@prasad\_kp](https://discuss.elastic.co/u/prasad_kp)\
**Post date:** [October 5, 2016, 11:29am UTC](https://discuss.elastic.co/t/make-pharse-prefix-search-on-whole-text-of-a-field/62263/1 "2016-10-05T11:29:35Z")

</div>

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,

---

<div class="post-metadata">

**Author:** ![nik9000](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nik9000/32/44947_2.png) [@nik9000](https://discuss.elastic.co/u/nik9000)\
**Post date:** [October 5, 2016, 11:44am UTC](https://discuss.elastic.co/t/make-pharse-prefix-search-on-whole-text-of-a-field/62263/2 "2016-10-05T11:44:19Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![prasad\_kp](https://avatars.discourse-cdn.com/v4/letter/p/dc4da7/32.png) [@prasad\_kp](https://discuss.elastic.co/u/prasad_kp)\
**Post date:** [October 5, 2016, 12:40pm UTC](https://discuss.elastic.co/t/make-pharse-prefix-search-on-whole-text-of-a-field/62263/3 "2016-10-05T12:40:41Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![prasad\_kp](https://avatars.discourse-cdn.com/v4/letter/p/dc4da7/32.png) [@prasad\_kp](https://discuss.elastic.co/u/prasad_kp)\
**Post date:** [October 5, 2016, 2:01pm UTC](https://discuss.elastic.co/t/make-pharse-prefix-search-on-whole-text-of-a-field/62263/4 "2016-10-05T14:01:26Z")

</div>

Hi Nik,  
Analyzer : settings

```auto
               "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:

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

```

M using this query

```auto
{
  "prefix" : {
    "suggestion" : {
      "prefix" : "lub"
    }
  }
}

```

Still m getting the unwanted result 😕

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

```

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

---

<div class="post-metadata">

**Author:** ![nik9000](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nik9000/32/44947_2.png) [@nik9000](https://discuss.elastic.co/u/nik9000)\
**Post date:** [October 5, 2016, 3:20pm UTC](https://discuss.elastic.co/t/make-pharse-prefix-search-on-whole-text-of-a-field/62263/5 "2016-10-05T15:20:07Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 5, 2017, 10:14pm UTC](https://discuss.elastic.co/t/make-pharse-prefix-search-on-whole-text-of-a-field/62263/6 "2017-07-05T22:14:42Z")

</div>


