PHP Search entries according to year indexed

I am using the PHP client to search and index documents into ES. I created a button with different values (2018, 2017, 2016) so that a user can find entries according to the date the entries were made (for example: view results for all entries in year 2016)

I separated the ES query using else-if statement, but it doesn't work. Here is the code:

if(isset($_GET['titel'], $_GET['beschreibung'], $_GET['thema'], $_GET['beitragstyp']/*, $_GET['veröffentlicht']*/, $_GET['date'])) {
      $titel = $_GET['titel'];
      $beschreibung = $_GET['beschreibung'];
      $thema = $_GET['thema'];
      $beitragstyp = $_GET['beitragstyp'];
      $date = $_GET['date'];

  if ($date === "2018") {
    $query = $client->search([
      'index' => 'my_index',
      'type' => 'default',
      'body' => [
        'query' => [
          'bool' => [
            'should' => [
              ['match_phrase' => ['Titel' => $titel]],
              ['match_phrase' => ['Beschreibung' => $beschreibung]],
              ['match_phrase' => ['Thema' => $thema]],
              ['match_phrase' => ['Beitragstyp' => $beitragstyp]],
              ['range' => [
                'Datum' => [
                  'gte' => '2018-01-01',
                  'lte' => '2018-12-31',
                  'format' => 'yyyy-MM-dd'
                ]
              ]]
            ]
          ]
        ]
      ]
    ]);
  } else if ($date === "2017") {
    $query = $client->search([
      'index' => 'my_index',
      'type' => 'default',
      'body' => [
        'query' => [
          'bool' => [
            'should' => [
              ['match_phrase' => ['Titel' => $titel]],
              ['match_phrase' => ['Beschreibung' => $beschreibung]],
              ['match_phrase' => ['Thema' => $thema]],
              ['match_phrase' => ['Beitragstyp' => $beitragstyp]],
              ['range' => [
                'Datum' => [
                  'gte' => '2017-01-01',
                  'lte' => '2017-12-31',
                  'format' => 'yyyy-MM-dd'
                ]
              ]]
            ]
          ]
        ]
      ]
    ]);
  } else if ($date === "2016") {
    $query = $client->search([
      'index' => 'my_index',
      'type' => 'default',
      'body' => [
        'query' => [
          'bool' => [
            'should' => [
              ['match_phrase' => ['Titel' => $titel]],
              ['match_phrase' => ['Beschreibung' => $beschreibung]],
              ['match_phrase' => ['Thema' => $thema]],
              ['match_phrase' => ['Beitragstyp' => $beitragstyp]],
              ['range' => [
                'Datum' => [
                  'gte' => '2016-01-01',
                  'lte' => '2016-12-31',
                  'format' => 'yyyy-MM-dd'
                ]
              ]]
            ]
          ]
        ]
      ]
    ]);
  } else {
    $query = $client->search([
      'index' => 'my_index',
      'type' => 'default',
      'body' => [
        'query' => [
          'bool' => [
            'should' => [
              ['match_phrase' => ['Titel' => $titel]],
              ['match_phrase' => ['Beschreibung' => $beschreibung]],
              ['match_phrase' => ['Thema' => $thema]],
              ['match_phrase' => ['Beitragstyp' => $beitragstyp]],
            ]
          ]
      ]
    ]
  ]);
  }

And this is how I am trying to get the different year values:

<select class="publishedDropdown" name="date">
    <option value="Empty">Date</option>
    <option value="2018">2018</option>
    <option value="2017">2017</option>
    <option value="2016">2016</option>
</select>

EDITED: It was a simple mistake. I changed the "=" to "===" in the if statement and it works.

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