# Elasticsearch/PHP Client: Using script to search for a month

**URL:** https://discuss.elastic.co/t/elasticsearch-php-client-using-script-to-search-for-a-month/123988
**Category:** Elasticsearch
**Created:** [March 14, 2018, 7:52pm UTC](https://discuss.elastic.co/t/elasticsearch-php-client-using-script-to-search-for-a-month/123988 "2018-03-14T19:52:31Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![syiannop](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/syiannop/32/26920_2.png) [@syiannop](https://discuss.elastic.co/u/syiannop)
#### Post date: [March 14, 2018, 7:52pm UTC](https://discuss.elastic.co/t/elasticsearch-php-client-using-script-to-search-for-a-month/123988/1 "2018-03-14T19:52:31Z")

</div>

I am trying to search for a specific month using the PHP client for ES. I tried the following code and it works fine in Kibana:

```
GET testba/_search
{
 "query": {
   "bool": {
    "must": [
     {
      "range": {
        "Datum": {
          "gte": "2000-01-01",
          "lte": "3000-12-31",
          "format": "yyyy-MM-dd"
         }
       }
     },
    { "script": { "script": "doc['Datum'].date.monthOfYear === 01 } }
   ]
  }
 }
}  

```

But when I try to do exactly the same thing in PHP I get no results back:

```
if ($months === "01") {
$query = $client->search([
  'index' => 'testba',
  'type' => 'doc',
  'body' => [
    'query' => [
      'bool' => [
        'should' => [
          ['match_phrase' => ['Titel' => '$titel']],
          ['match_phrase' => ['Beschreibung' => $beschreibung]],
          ['match_phrase' => ['Thema' => $thema]],
          ['match_phrase' => ['Beitragstyp' => $beitragstyp]],
          ['range' => [
            'Datum' => [
              'gte' => '2000-01-01',
              'lte' => '3000-01-31',
              'format' => 'yyyy-MM-dd'
            ]
          ]
        ],
        [ 
          'script' => [
          ['script' => ['doc[\'Datum\'].date.monthOfYear === 01']]
          ]
        ]
      ]
    ]
  ]
]
]);
}

```

I think I might be doing something wrong with the ' ' on the ['Datum'] part. I also tried without them and with " ", but still nothing.

---

<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: [April 11, 2018, 7:52pm UTC](https://discuss.elastic.co/t/elasticsearch-php-client-using-script-to-search-for-a-month/123988/2 "2018-04-11T19:52:34Z")

</div>

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