# Filter data from field name on elasticsearch-PHP

**URL:** <https://discuss.elastic.co/t/filter-data-from-field-name-on-elasticsearch-php/268>\
**Category:** Elasticsearch\
**Created:** [May 6, 2015, 9:02am UTC](https://discuss.elastic.co/t/filter-data-from-field-name-on-elasticsearch-php/268 "2015-05-06T09:02:41Z")\
**Posts on this page:** 8\
**Page:** 2

<div class="post-metadata">

**Author:** ![DamPe](https://avatars.discourse-cdn.com/v4/letter/d/e19b73/32.png) [@DamPe](https://discuss.elastic.co/u/DamPe)\
**Post date:** [May 13, 2015, 10:48am UTC](https://discuss.elastic.co/t/filter-data-from-field-name-on-elasticsearch-php/268/21 "2015-05-13T10:48:08Z")

</div>

@Camilo_Sierra: I tried this one too.Data is returning.But still i cant see the difference.

[quote="Camilo\_Sierra, post:20, topic:268"]  
"term": {  
"phone\_mobile": 465  
}  
},  
{  
"term": {

```
  "phone_home": 465
                }

```

[/quote] In here you should have "" for numbers like this.

```
      "phone_home": "465"

```

Otherwise without quotes, will return an error.

---

<div class="post-metadata">

**Author:** ![Camilo\_Sierra](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/camilo_sierra/32/14397_2.png) [@Camilo\_Sierra](https://discuss.elastic.co/u/Camilo_Sierra)\
**Post date:** [May 13, 2015, 11:22am UTC](https://discuss.elastic.co/t/filter-data-from-field-name-on-elasticsearch-php/268/22 "2015-05-13T11:22:06Z")

</div>

i will tried to explain with sql terms, maybe it will be easy to understand!  
we have a should because it can be p\_mobile or p\_home (sql OR) but inside the "should" query for one condition we will add a must (is inside OR query add AND options) bool allow us to encapsulate the exist filter and the term filter.

the first query that i send you is the literally traduction of :

> [@DamPe](#):
>
> First i Need to check that 'phone\_mobile' column is blank or not, if it is not blank, then check whether 'phone\_mobile' column has the value '456'

the exist check if the field is empty or not and the terms if the value correspond.

but we can do easier, in the last query we forget php and think in elasticsearch mode, we like to get all the documents that had p\_mobile or p\_home with a value of 465, so we don't need to know if exist or not because the only think that is important is that my fields correspond to my value 465.

---

<div class="post-metadata">

**Author:** ![Camilo\_Sierra](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/camilo_sierra/32/14397_2.png) [@Camilo\_Sierra](https://discuss.elastic.co/u/Camilo_Sierra)\
**Post date:** [May 13, 2015, 11:26am UTC](https://discuss.elastic.co/t/filter-data-from-field-name-on-elasticsearch-php/268/23 "2015-05-13T11:26:22Z")

</div>

normaly if your mapping is defined as a integer you dont need to use the " " ! check the type for phone\_home, and phone\_mobile and is not at integer defined in your template or mapping file and reindex

[http://www.elastic.co/guide/en/elasticsearch/reference/current/indices-get-mapping.html](http://www.elastic.co/guide/en/elasticsearch/reference/current/indices-get-mapping.html)

---

<div class="post-metadata">

**Author:** ![DamPe](https://avatars.discourse-cdn.com/v4/letter/d/e19b73/32.png) [@DamPe](https://discuss.elastic.co/u/DamPe)\
**Post date:** [May 14, 2015, 7:07am UTC](https://discuss.elastic.co/t/filter-data-from-field-name-on-elasticsearch-php/268/24 "2015-05-14T07:07:18Z")

</div>

@Camilo_Sierra:ok now i get it.so can we do a search using AND ,OR operators?

```
phone_mobile=456 AND first_name=ABC

```

kind of queries?

---

<div class="post-metadata">

**Author:** ![Camilo\_Sierra](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/camilo_sierra/32/14397_2.png) [@Camilo\_Sierra](https://discuss.elastic.co/u/Camilo_Sierra)\
**Post date:** [May 15, 2015, 8:03am UTC](https://discuss.elastic.co/t/filter-data-from-field-name-on-elasticsearch-php/268/25 "2015-05-15T08:03:43Z")

</div>

technically yes you can use and/or, but the problem is that "and"/"or" dont use bitsets, you boost your query performance using bitsets.

more information :  
[https://www.elastic.co/blog/all-about-elasticsearch-filter-bitsets](https://www.elastic.co/blog/all-about-elasticsearch-filter-bitsets)

---

<div class="post-metadata">

**Author:** ![Hilal](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/hilal/32/7684_2.png) [@Hilal](https://discuss.elastic.co/u/Hilal)\
**Post date:** [February 4, 2016, 10:24am UTC](https://discuss.elastic.co/t/filter-data-from-field-name-on-elasticsearch-php/268/26 "2016-02-04T10:24:38Z")

</div>

Please help me. I am using php 5.5 and Elasticsearch 2.1. I want to do ranking among history. But my date filter does not work correctly.

I am getting accurate results when I made query only between the dates.However, I am not getting accurate results when I made query with date mont, day and hour.

For example :

[http://10.0.2.15:8080/filter.php?my\_date\_try&my\_date\_lte=2017/12/3123:59:59&my\_date\_gte=2016/01/0100:00:00](http://10.0.2.15:8080/filter.php?my_date_try&my_date_lte=2017/12/3123:59:59&my_date_gte=2016/01/0100:00:00)

Result is not correct.

Example 2:

[http://10.0.2.15:8080/filter.php?my\_date\_try&my\_date\_lte=2017&my\_date\_gte=2016](http://10.0.2.15:8080/filter.php?my_date_try&my_date_lte=2017&my_date_gte=2016)

Result is correct.

My date mapping :

$myTypeMapping['properties']['my\_date']['type']='date';

$myTypeMapping['properties']['my\_date']['index']='not\_analyzed';

$myTypeMapping['properties']['my\_date']['format']='yyyy/MM/dd HH:mm:ss';  
My date filter :

unset($filter\_my\_date);

if(isset($\_GET[my\_date\_try])){

$filter\_my\_date['range']['my\_date']['lte']=$\_GET['my\_date\_lte'];

$filter\_my\_date['range']['my\_date']['gte']=$\_GET['my\_date\_gte'];

$filter\_my\_date['range']['my\_date']['format']='yyyy/MM/dd HH:mm:ss';  
}

if(is\_array($filter\_my\_date)){

$searchParams['body']['query']['bool']['must']=$filter\_my\_date;

}

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [February 4, 2016, 10:50am UTC](https://discuss.elastic.co/t/filter-data-from-field-name-on-elasticsearch-php/268/27 "2016-02-04T10:50:36Z")

</div>

Please start your own thread.

---

<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:18pm UTC](https://discuss.elastic.co/t/filter-data-from-field-name-on-elasticsearch-php/268/28 "2017-07-05T23:18:57Z")

</div>

Closed on July 5, 2017, 11:18pm UTC



[Previous page](https://discuss.elastic.co/t/filter-data-from-field-name-on-elasticsearch-php/268.md?page=1)
