好的想法是十分钱一打,真正无价的是能够实现这些想法的人。

父子查询排序

Elasticsearch | 作者 huangming | 发布于2019年01月26日 | 阅读数:2986

这个是数据结构
PUT hotel
{
  "mappings": {
    "hotel_search": {
      "properties": {
        "hotel_price_storage": {
          "type": "join",
          "relations": {
            "hotel": "price_storage"
          }
        }
      }
    }
  }
}
 
这个是数据
PUT hotel/hotel_search/7?refresh
{
  "hotelCode": 369, 
  "hotelName": "新测试", 
  "brandName": "我是一条测试数据", 
  "cityId": 310100,
  "hotel_price_storage": {
    "name": "hotel" 
  }
}

PUT hotel/hotel_search/8?routing=7&refresh
{
  "date": "2019-01-26",
  "price": 30,
  "inventory": 40,
  "hotelCode": 369, 
  "hotel_price_storage": {
    "name": "price_storage",
    "parent": "7" 
  }
}


PUT hotel/hotel_search/9?routing=7&refresh
{
  "date": "2019-01-27",
  "price": 1,
  "inventory": 40,
  "hotelCode": 369, 
  "hotel_price_storage": {
    "name": "price_storage",
    "parent": "7" 
  }
}
 
这个是我的查询dsl
POST hotel/_search
{
  "query": {
    "has_child": {
      "type": "price_storage",
      "score_mode": "min",
      "inner_hits": {
        "sort": [
          {
            "date": {
              "order": "asc"
            }
          }
        ]
      },
      "min_children": 2,
      "query": {
        "function_score": {
          "query": {
                 "match_all": {}
            },
          "functions": [
            {
              "field_value_factor": {
                "field": "price"
              }
            }
          ]
        }
      }
    }
  },
  "sort": [
    {
      "_score": {
        "order": "asc"
      }
    }
  ]
}
 
现在我要通过查询第一天的价格信息进行排序,
比如我查2019-01-26 至2019-01-29,就按2019-01-26当天的价格排序,
如果我查2019-02-01 至2019-02-03,就按2019-02-01当天的价格排序,
现在应该怎么写查询呢?求指教啊
已邀请:

aa1356889

赞同来自:

撸主搞定了吗

forwujinwei

赞同来自:

搞定了吗?遇到类似的问题,酒店模型关联太深,查询是需要从报价表中获取有效的报价,以及可能会查询不同房型下的报价

zcc_vv - 95

赞同来自:

想要按照前面那一天的排序那子节点就要能把这个价格通过分带给父节点。可以在子节点里对最早的一天单独用价格打分,其他时间的都不给分,只用filter召回就好了。然后再父节点侧排序就好了

要回复问题请先登录注册