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

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.

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