# Elasticsearch string query url with PHP and cURL

**URL:** <https://discuss.elastic.co/t/elasticsearch-string-query-url-with-php-and-curl/26985>\
**Category:** Elasticsearch\
**Created:** [August 6, 2015, 3:32pm UTC](https://discuss.elastic.co/t/elasticsearch-string-query-url-with-php-and-curl/26985 "2015-08-06T15:32:47Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![TomS](https://avatars.discourse-cdn.com/v4/letter/t/53a042/32.png) [@TomS](https://discuss.elastic.co/u/TomS)\
**Post date:** [August 6, 2015, 3:32pm UTC](https://discuss.elastic.co/t/elasticsearch-string-query-url-with-php-and-curl/26985/1 "2015-08-06T15:32:47Z")

</div>

I am using elasticsearch to get some kind of information about my users.

I just made a script in PHP that parses a document by using cURL and it is sending requests like:

[http://something.something/test\*/\_search?q=%2Blogin:"jack"%20%2Bdate:"\*May%20%20%201"%20%2Broom:"nameOfRoom"&default\_operator=AND&size=99999999](http://something.something/test*/_search?q=%2Blogin:%22jack%22%20%2Bdate:%22*May%20%20%201%22%20%2Broom:%22nameOfRoom%22&default_operator=AND&size=99999999)

Which, decoded, is:

[http://something.something/test\*/\_search?q=+login:"jack"](http://something.something/test*/_search?q=+login:%22jack%22) +date:"\*May 1" +room:"nameOfRoom"&default\_operator=AND&size=99999999

Instead of getting records about Jack from May 1st (yeah there is triple space) that was in the "nameOfRoom" room I am getting stuff from whole May with logins like "--jack" "\*jack" etc.  
Can someone provide info how to build more complicated query like this?  
Regards Tom

---

<div class="post-metadata">

**Author:** ![marafee1243](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/marafee1243/32/3971_2.png) [@marafee1243](https://discuss.elastic.co/u/marafee1243)\
**Post date:** [August 6, 2015, 6:01pm UTC](https://discuss.elastic.co/t/elasticsearch-string-query-url-with-php-and-curl/26985/2 "2015-08-06T18:01:04Z")

</div>

did you try with PHP url urldecode & urlencode.

---

<div class="post-metadata">

**Author:** ![TomS](https://avatars.discourse-cdn.com/v4/letter/t/53a042/32.png) [@TomS](https://discuss.elastic.co/u/TomS)\
**Post date:** [August 6, 2015, 7:06pm UTC](https://discuss.elastic.co/t/elasticsearch-string-query-url-with-php-and-curl/26985/3 "2015-08-06T19:06:57Z")

</div>

Thanks for the response. Yeah I've tried in that way but it keep showing me too much records (like --jack, \*jack and wrong dates [from May but not only from 1st) ☹

---

<div class="post-metadata">

**Author:** ![polyfractal](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/polyfractal/32/48162_2.png) [@polyfractal](https://discuss.elastic.co/u/polyfractal)\
**Post date:** [August 7, 2015, 12:02am UTC](https://discuss.elastic.co/t/elasticsearch-string-query-url-with-php-and-curl/26985/4 "2015-08-07T00:02:52Z")

</div>

It's likely an analyzer problem, not a PHP encoding problem. Your date field looks to be a string, not an actual Date. That means when you search for `May 1`, it is actually tokenized into `["may", "1"]`. So any document that has the term "may" will match.

If you haven't specified a mapping yourself, you'll need to read up on Mappings and Analyzers, configure the date field to be a real Date, then use a Range filter/query to check the date.

Also, I'd recommend using the Query DSL instead of `q=` params, it is a lot more flexible. And there's also [an official PHP client][1], which can make life easier 🙂  
[1]: [https://github.com/elastic/elasticsearch-php/](https://github.com/elastic/elasticsearch-php/)

---

<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, 11:57pm UTC](https://discuss.elastic.co/t/elasticsearch-string-query-url-with-php-and-curl/26985/5 "2017-07-05T23:57:02Z")

</div>


