Cant get the date range to work Elastic search 2.0


(Janaka Bandara) #1

Hi, I have following mapping inserted,

'searchable_tags' => array(
    'type' => 'string',

),
    'listing_type' => array(
        'type' => 'string'
    ),
    'listing_id' => array(
        'type' => 'integer'
    ),
    'from_date' => array(
        'type' => 'date',
        'format' => 'yyyy-MM-dd HH:mm:ss'
    ),
    'to_date' => array(
        'type' => 'date',
        'format' => 'yyyy-MM-dd HH:mm:ss'
    ),

And I'm trying to filter the result by date by running following query

'query' => [
    'bool' => [
        'must' => [
            'common' => [
                "searchable_tags" => [
                    "query" => $searchString,
                    "cutoff_frequency" => 0.001
                ]
            ]
        ],
        'filter' => [
            'range' => [
                'from_date' => [
                    [
                        'lte' => '2015-01-01',
                        "format" => "yyyy-MM-dd"
                    ]
                ]
            ]
        ],
        'must' => [
            'term' => [
                'listing_type' => $listingType
            ]
        ]

    ],
],

But it returns all the result despite the date range filter. Date range filter was working fine with ES 1.7 but I cant get it to work with 2.0

Could someone help me with this? whats am I doing wrong here

thanks


(David Pilato) #2

Pretty unsure but it sounds like you added two must parts instead of two must clauses in a must part.

Not sure if it's your issue but it looks incorrect to me.


(Janaka Bandara) #3

Thanks for the reply, This may be a stupid question but I'm new to elastic search and 2.0 changes not helping me at all. So whats the difference between must parts and must clauses?


(David Pilato) #4

I meant that all inner must clauses must be wrapped under a must array.
Have a look at the should part in the doc example. This form applies to must as well: https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-bool-query.html?q=Bool


(Janaka Bandara) #5

Ah got it. Anyway the problem was with mapping it seems. Had to delete the index and re map, to get it working. Odd issue. anyway thanks a lot for the help and for the tip about clauses.


(system) #6