# Best Query for URLs

**URL:** <https://discuss.elastic.co/t/best-query-for-urls/11900>\
**Category:** Elasticsearch\
**Created:** [May 9, 2013, 1:40pm UTC](https://discuss.elastic.co/t/best-query-for-urls/11900 "2013-05-09T13:40:23Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kubes](https://avatars.discourse-cdn.com/v4/letter/k/a9adbd/32.png) [@Kubes](https://discuss.elastic.co/u/Kubes)\
**Post date:** [May 9, 2013, 1:40pm UTC](https://discuss.elastic.co/t/best-query-for-urls/11900/1 "2013-05-09T13:40:23Z")

</div>

I am using Elasticsearch w/ logstash, currently running .20, but will be  
moving to .90 soo.

What is the best means (both in .20 and .90) to search for url matching?  
I was using a a match, but it tokenized the query? I want to more like  
^/my\_url.\*. I understand regex/wildards are inefficient searches?  
{  
"match": {  
"@fields.request\_uri": {  
"query": "/site/api/call\_data.json"  
}  
}  
}

I do also have a mapping for the "raw" field (non-analyzed)

Thanks!

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![radu\_gheorghe](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/radu_gheorghe/32/556_2.png) [@radu\_gheorghe](https://discuss.elastic.co/u/radu_gheorghe)\
**Post date:** [May 10, 2013, 3:24pm UTC](https://discuss.elastic.co/t/best-query-for-urls/11900/2 "2013-05-10T15:24:48Z")

</div>

Hello,

I think you'd be better off by defining a custom analyzer, where you'd use  
the Pathhierarchy  
Tokenizer[http://www.elasticsearch.org/guide/reference/index-modules/analysis/pathhierarchy-tokenizer/](http://www.elasticsearch.org/guide/reference/index-modules/analysis/pathhierarchy-tokenizer/).  
This way you'd be able to search for ^/my\_url.\* by running a simple term  
query for "/myurl". That would be faster than the match query, and waay  
faster than regex/wildcards, which are indeed slow.

## Best regards, Radu

[http://sematext.com/](http://sematext.com/) -- Elasticsearch -- Solr -- Lucene

On Thu, May 9, 2013 at 4:40 PM, Kubes [philip@freepricealerts.com](mailto:philip@freepricealerts.com) wrote:

> I am using Elasticsearch w/ logstash, currently running .20, but will be  
> moving to .90 soo.
> 
> What is the best means (both in .20 and .90) to search for url matching?  
> I was using a a match, but it tokenized the query? I want to more like  
> ^/my\_url.\*. I understand regex/wildards are inefficient searches?  
> {  
> "match": {  
> "@fields.request\_uri": {  
> "query": "/site/api/call\_data.json"  
> }  
> }  
> }
> 
> I do also have a mapping for the "raw" field (non-analyzed)
> 
> Thanks!
> 
> --  
> You received this message because you are subscribed to the Google Groups  
> "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an  
> email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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 6, 2017, 2:37am UTC](https://discuss.elastic.co/t/best-query-for-urls/11900/3 "2017-07-06T02:37:10Z")

</div>


