Elasticsearch date range intersection

前端 未结 1 1860

I\'m storing something like the following information in elastic search:

{ \"timeslot_start_at\" : \"2013-02-01\", \"timeslot_end_at\" : \"2013-02-03\" }
         


        
相关标签:
1条回答
  • 2021-02-20 03:04

    Update: It is now possible to use date_range data type that was added in elasticsearch v5.2. For an earlier version of elasticsearch the following solution still applies.

    To test for intersection, you should combine two range queries into a single query using bool query:

    {
        "bool": {
            "must": [
                {
                    "range": {
                        "timeslot_start_at": {
                            "lte": "2013-02-28"
                        }
                    }
                },
                {
                    "range": {
                        "timeslot_end_at": {
                            "gte": "2013-02-03"
                        }
                    }
                }
            ]
        }
    }
    
    0 讨论(0)
提交回复
热议问题