# Search as you type not returning expected result

**URL:** <https://discuss.elastic.co/t/search-as-you-type-not-returning-expected-result/50019>\
**Category:** Elasticsearch\
**Created:** [May 13, 2016, 6:00pm UTC](https://discuss.elastic.co/t/search-as-you-type-not-returning-expected-result/50019 "2016-05-13T18:00:35Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![aarangara](https://avatars.discourse-cdn.com/v4/letter/a/ccd318/32.png) [@aarangara](https://discuss.elastic.co/u/aarangara)\
**Post date:** [May 13, 2016, 6:00pm UTC](https://discuss.elastic.co/t/search-as-you-type-not-returning-expected-result/50019/1 "2016-05-13T18:00:35Z")

</div>

I have created and index with 1 shard and have 999 documents for a type.

I am trying to implement a search as you type query which is not working as expected.

The fields in documents have almost similar data and I want to enable search for all fields.

I have value for field **f4** in my type as "Proj1", "Proj2", "Proj3"...... till "Proj999" .

Example document **(all documents have almost similar data except field f4 which has success values as mentioned above like "Proj1", "Proj2", "Proj3".....)**

```
      {
            "_index": "myindex",
            "_type": "mytype",
            "_id": "42",
            "_score": 1,
            "_source": {
                "f1": "396","f2": "125650","f3": "BH.1511AI.001",
                "f4": "Proj1",
                "f5": "BH.1511AI.001","f6": "","f7": "","f8": "","f9": "","f10": "","f11": "","f12": "","f13": "","f14": "","f15": "","f16": "09/05/16 | 01:02PM | User","deleted": "0"
            }
        }

```

When I try to do a search for "Proj1", using following query

```
    {
     "index": "myindex",
    "type": "mytype",
    "body": {
        "query": {
            "multi_match": {
                "query": "proj1",
                "type": "cross_fields",
                "operator": "and",
                "fields": "f*",
                "analyzer":"standard"
            }
        }
    }
} 

```

I am getting documents like "Proj10", "Proj11","Proj12", "Proj100",......"Proj1",..... so on.

**I wanted that "Proj1" should be returned first in the search response for query string "Proj1", but it doesn't.**

I am using edgeNgram filter for indexing my documents which looks like (I am using php)

```
//analyzer
"myNGramAnalyzer" => [
       "type" => "custom",
        "char_filter" => ["html_strip"],
        "tokenizer" => "standard",
        "filter" => ["lowercase","standard","asciifolding","stop","snowball","ngram_filter"]
  ]
//filter settings
  "filter" => [
        "ngram_filter" => [
            "type" => "edgeNGram",
            "min_gram" => "2",
            "max_gram" => "20"
        ]
  ]
```

---

<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:51pm UTC](https://discuss.elastic.co/t/search-as-you-type-not-returning-expected-result/50019/2 "2017-07-05T22:51:32Z")

</div>


