Welcome, guest! Login / Register - Why register?
Psst.. new poll here.
[email protected] webmail now available. Want one? Go here.
Cannot use outlook/hotmail/live here to register as they blocking our mail servers. #microsoftdeez
Obey the Epel!

Paste

Pasted as JSON by tomm ( 5 years ago )
POST atest/offer/_mapping
{
  "offer":{
    "properties":{
      "offerId": {"type": "integer"},
      "hotelName": {"type": "text"},
      "variants": {
          "type": "nested",
          "properties": {
            "packageRoomSetId": {"type": "integer"},
            "packageId": {"type": "integer"},
            "roomId": {"type": "integer"},
            "p1": {"type": "integer"},
            "p2": {"type": "integer"},
            "price": {"type":"float"},
            "variants_dates": {
              "type": "nested",
              "properties": {
                  "date": {
                    "type": "date",
                    "format": "yyy-MM-dd"
                  },
                  "price": {"type": "float"}
              }
            }
          }
      }
    }
  }
}

PUT atest/offer/1
{
  "offerId": 99,
  "hotelName": "oferta1 ",
  "variants": [
    {
      "packageRoomSetId": 23,
      "packageId": 2, 
      "roomId": 3,
      "p1": 99,
      "p2": 99,
      "price": 66.66,
      "variants_dates": 
      [
        {
          "date": "2019-02-01",
          "price": 1500
        },
        {
          "date": "2019-02-02",
          "price": 300
        },
        {
          "date": "2019-02-03",
          "price": 1000
        }
      ]
    },
    {
      "packageRoomSetId": 153,
      "packageId": 15, 
      "roomId": 3,
      "p1": 99,
      "p2": 17,
      "price": 66.66,
      "variants_dates": 
      [
        {
          "date": "2019-02-01",
          "price": 150
        },
        {
          "date": "2019-02-02",
          "price": 1
        },
        {
          "date": "2019-02-03",
          "price": 1000
        }
      ]
    },
    {
      "packageRoomSetId": 1532,
      "packageId": 15, 
      "roomId": 3,
      "p1": 99,
      "p2": 99,
      "price": 106.66,
      "variants_dates": 
      [
        {
          "date": "2019-02-01",
          "price": 220
        },
        {
          "date": "2019-02-02",
          "price": 220
        },
        {
          "date": "2019-02-03",
          "price": 1000
        }
      ]
    }
  ]
}
PUT atest/offer/2
{
  "offerId": 188,
  "hotelName": "oferta2 ",
  "variants": [
    {
      "packageRoomSetId": 200300,
      "packageId": 200, 
      "roomId": 300,
      "p1": 99,
      "p2": 99,
      "price": 66.66,
      "variants_dates": 
      [
        {
          "date": "2019-02-01",
          "price": 1500
        },
        {
          "date": "2019-02-02",
          "price": 300
        },
        {
          "date": "2019-02-03",
          "price": 44000
        }
      ]
    }
  ]
}
    GET atest/_search
    {
      "query": {
        "bool": {
          "must": {
            "nested": {
              "path": "variants",
              "query": {
                "bool": {
                  "must": [
                    {
                      "nested": {
                        "path": "variants.variants_dates",
                        "query": {
                          "term": {
                            "variants.variants_dates.date": {
                              "value": "2019-02-01"
                            }
                          }
                        }
                      }
                    },
                    {
                      "nested": {
                        "path": "variants.variants_dates",
                        "query": {
                          "term": {
                            "variants.variants_dates.date": {
                              "value": "2019-02-02"
                            }
                          }
                        }
                      }
                    }
                  ]
                }
              }
            }
          }
        }
      },
      "size": 0,
      "aggs": {
        "offers": {
          "terms": {
            "field": "offerId"
          },
          "aggs": {
            "variants": {
              "nested": {
                "path": "variants"
              },
              "aggs": {
                "variant": {
                  "terms": {
                    "field": "variants.packageRoomSetId"
                  },
                  "aggs": {
                    "variant-sum": {
                      "nested": {
                        "path": "variants.variants_dates"
                      },
                      "aggs": {
                        "sum-filter": {
                          "filters": {
                            "filters": {
                              "sum-filters": {
                                "range": {
                                  "variants.variants_dates.date": {
                                    "gte": "2019-02-01",
                                    "lte": "2019-02-02",
                                    "format": "yyyy-MM-dd"
                                  }
                                }
                              }
                            }
                          },
                          "aggs": {
                            "dates-sum": {
                              "sum": {
                                "field": "variants.variants_dates.price"
                              }
                            },
                            "sum-bucket-sort": {
                              "bucket_sort": {
                                "sort": [
                                  {
                                    "dates-sum": {
                                      "order": "desc"
                                    }
                                  }
                                ],
                                "size": 1
                              }
                            }
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }

 

Revise this Paste

Your Name: Code Language: