弹性搜索顺序日期 [英] Elasticsearch sequential dates

查看:90
本文介绍了弹性搜索顺序日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Elasticsearch创建一个酒店预订系统,并尝试找到一种方式来返回具有可变数量的连续日期的酒店(例如7天),范围内的日期

I am creating a hotel booking system using Elasticsearch and am trying to find a way to return hotels that have a variable number of sequential dates available (for example 7 days) across a range of dates

我目前正在将酒店的日期和价格作为小孩文件存入酒店,但我不确定如何进行搜索,或者是否可以使用我目前的设置?

I am currently storing dates and prices as a child document to the hotel but am unsure how to undertake the search or if it is even possible with my current setup?

编辑:添加映射

酒店映射

{
  "hotel":{
    "properties":{
      "city":{
        "type":"string"
      },
      "hotelid":{
        "type":"long"
      },
      "lat":{
        "type":"double"
      },
      "long":{
        "type":"double"
      },
      "name":{
        "type":"multi_field",
        "fields":{
          "name":{
            "type":"string"
          },
          "name.exact":{
            "type":"string",
            "index":"not_analyzed",
            "omit_norms":true,
            "index_options":"docs",
            "include_in_all":false
          }
        }
      },
      "star":{
        "type":"double"
      }
    }
  }
}

日期映射

{
    "dates": {
        "_parent": {
            "type": "hotel"
        },
        "_routing": {
            "required": true
        },
        "properties": {
            "date": {
                "type": "date",
                "format": "dateOptionalTime"
            },
            "price": {
                "type": "double"
            }
        }
    }
}

我目前正在使用日期范围来选择可用日期,然后使用字段查询来匹配城市 - 其他领域将在以后使用/ p>

I am currently using a date range to select the available dates and then a field query to match the city - the other fields will be used later

推荐答案

我不得不做类似的事情,最后我每天在酒店(房间)被索引时预订。 (所以[2014-02-15,2014-02-16,2014-02-17等]的列表)

I had to to something similar and i ended up storing every day the hotel(room) was booked during indexing. (So a list of [2014-02-15, 2014-02-16, 2014-02-17, etc])

之后,这是一个童话琐事的写查询在特定日期范围内查找所有酒店房间是免费的。

After that is was fairy trivial to write a query to find all hotel rooms that were free during a certain date range.

仍然似乎应该有优雅的解决方案,但这最终为我工作非常好。

Still seems like there should be am ore elegant solution, but this ended up working great for me.

这篇关于弹性搜索顺序日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆