# Search results with begins with and ending with using wildcard

**URL:** <https://discuss.elastic.co/t/search-results-with-begins-with-and-ending-with-using-wildcard/117687>\
**Category:** Elasticsearch\
**Created:** [January 30, 2018, 6:56pm UTC](https://discuss.elastic.co/t/search-results-with-begins-with-and-ending-with-using-wildcard/117687 "2018-01-30T18:56:39Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![RohanKumbhar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rohankumbhar/32/23649_2.png) [@RohanKumbhar](https://discuss.elastic.co/u/RohanKumbhar)\
**Post date:** [January 30, 2018, 6:56pm UTC](https://discuss.elastic.co/t/search-results-with-begins-with-and-ending-with-using-wildcard/117687/1 "2018-01-30T18:56:39Z")

</div>

Hi ,

I using custom search /index analyzer as shown below

```
 "settings": {
    "index": {
      "analysis": {
        "analyzer": {
          "custom_search_analyzer": {
            "filter": [
              "lowercase",
              "asciifolding"
            ],
            "type": "custom",
            "tokenizer": "whitespace"
          },
          "custom_index_analyzer": {
            "filter": [
              "lowercase",
              "asciifolding"
            ],
            "type": "custom",
            "tokenizer": "custom_tokenizer"
          }
        },
        "tokenizer": {
          "custom_tokenizer": {
            "type": "ngram",
            "min_gram": "1",
            "max_gram": "10"
          }
        }
      }
    }
  },
  "mappings": {
    "doc": {
      "properties": {
        "my_field": {
          "type": "text",
          "analyzer": "custom_index_analyzer",
          "search_analyzer": "custom_search_analyzer",
          "fields": {
            "keyword": {
              "ignore_above": 256,
              "type": "keyword"
            }
          }
        }
      }
    }

```

But the problem with this analyzer is when user searches with wildcard query

> file\*

and expecting results which begins with file but it returns the results like

1. my\_field=myfile.txt  
2.my\_field=samplefile.txt

but i want only those results which starts with file , i have tried with prefix query and also match\_phase\_prefix query but its not working either

Case 2: if user is searching for \*.txt then it should return all the documents which is ending with .txt only and not the results which .txt in between.. please help to implement the same?  
Kindly help

thanks,  
rohan

---

<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:** [February 27, 2018, 6:56pm UTC](https://discuss.elastic.co/t/search-results-with-begins-with-and-ending-with-using-wildcard/117687/2 "2018-02-27T18:56:52Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
