# Longest prefix match

**URL:** https://discuss.elastic.co/t/longest-prefix-match/257722
**Category:** Elasticsearch
**Created:** [December 5, 2020, 8:13am UTC](https://discuss.elastic.co/t/longest-prefix-match/257722 "2020-12-05T08:13:09Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![sumanthmitra](https://avatars.discourse-cdn.com/v4/letter/s/ea5d25/32.png) [@sumanthmitra](https://discuss.elastic.co/u/sumanthmitra)
#### Post date: [December 5, 2020, 8:13am UTC](https://discuss.elastic.co/t/longest-prefix-match/257722/1 "2020-12-05T08:13:09Z")

</div>

Hi,  
I am not able to figure out how to achieve the longest prefix match between the search query and the stored doc values.  
Say we have the below doc values indexed.  
"ababab"  
"ab"  
"a"  
and if the input query is "abababc", I need to match the first doc value.  
Is this possible with elasticsearch.  
Appreciate any help.

---

<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: [January 2, 2021, 8:13am UTC](https://discuss.elastic.co/t/longest-prefix-match/257722/2 "2021-01-02T08:13:11Z")

</div>

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