Skip to content

Instantly share code, notes, and snippets.

@lukebyrne
Last active May 20, 2017 03:57
Show Gist options
  • Save lukebyrne/d490d1c97bdaf684db404e4ba0237e92 to your computer and use it in GitHub Desktop.
Save lukebyrne/d490d1c97bdaf684db404e4ba0237e92 to your computer and use it in GitHub Desktop.

Problem

We have an issue with the querying of our API, specifically the count of stores that get returned for a query, lat/lng versus a product_id, lat/lng.

First API Call

One the first API call (use postman, curl or a plain browser to view results)

https://app.frootbat.com/api/v4/products_group_by_sizes?lat=36.778261&lng=-119.4179324&page=1&query=Suntory%20Hibiki%20Limited%2017%20Year%20Old%20Blended%20Whisky%20750

We are quering for Suntory Hibiki Limited 17 Year Old Blended Whisky 750 at a lat/lng of 37.8857582/-122.1180201.

We get the following response:

{
  "results": [
    {
      "lowPrice": 169.99,
      "avgPrice": 313.44,
      "highPrice": 699.99,
      "id": 459295,
      "name": "Hibiki Limited Edition 17 Year Old Blended Whisky",
      "brandId": 15470,
      "brandName": "Suntory",
      "brandProductName": "Suntory Hibiki Limited Edition 17 Year Old Blended Whisky",
      "container": "bottle",
      "displaySize": "750ml",
      "packaging": "Single",
      "pricesCount": 11,
      "productIds": [
        459295
      ],
      "years": [
        ""
      ],
      "relevancyScore": "0.97",
      "elasticScore": 44.276443,
      "images": {
        "thumb": "https://dw95zbr0bn7mn.cloudfront.net/compare/asset/21816/thumb_compare::product-459295-017052ba-0797-4a04-9a21-f476a0dc5a89.jpg",
        "small": "https://dw95zbr0bn7mn.cloudfront.net/compare/asset/21816/small_compare::product-459295-017052ba-0797-4a04-9a21-f476a0dc5a89.jpg",
        "large": "https://dw95zbr0bn7mn.cloudfront.net/compare/asset/21816/large_compare::product-459295-017052ba-0797-4a04-9a21-f476a0dc5a89.jpg"
      }
    }
  ],
  "filters": {
    "productContainer": {
      "displayName": "Container",
      "options": [
        {
          "filterValue": "bottle",
          "count": 1,
          "displayName": "Bottle"
        }
      ]
    },
    "productTypeName": {
      "displayName": "Type Name",
      "options": [
        {
          "filterValue": "Liquor",
          "count": 1,
          "displayName": "Liquor"
        }
      ]
    },
    "productCountry": {
      "displayName": "Country",
      "options": [
        {
          "filterValue": "Japan",
          "count": 1,
          "displayName": "Japan"
        }
      ]
    },
    "productYears": {
      "displayName": "Years",
      "options": []
    },
    "productPackaging": {
      "displayName": "Packaging",
      "options": [
        {
          "filterValue": "Single",
          "count": 1,
          "displayName": "Single"
        }
      ]
    }
  }
}

The issue is the low_price, average_price and high_price and the pricesCount.

pricesCount returns as 11, which is the number of stores in the nested stores index.

Its seems that the query is ignoring the filtering for stores geolocation and is including all stores in its calcs. We are querying index compare-product_searches_group_by_sizes and the query is in this Gist as query1.json.

Second API Call

On the second API call (use postman, curl or a plain browser to view results)

https://app.frootbat.com/api/v4/products_group_by_sizes/459295?lat=37.8857582&lng=-122.1180201

We are asking for product_id for 459295 at a lat/lng of 37.8857582/-122.1180201.

We get the following response:

{
  "lowPrice": 199.99,
  "avgPrice": 372.57,
  "highPrice": 699.99,
  "id": 459295,
  "name": "Hibiki Limited Edition 17 Year Old Blended Whisky",
  "brandId": 15470,
  "brandName": "Suntory",
  "container": "bottle",
  "displaySize": "750ml",
  "packaging": "Single",
  "pricesCount": 7,
  "productIds": [
    459295
  ],
  "years": [
    ""
  ],
  "relevancyScore": "0.97",
  "description": "",
  "country": "Japan",
  "rank": null,
  "images": {
    "thumb": "https://dw95zbr0bn7mn.cloudfront.net/compare/asset/21816/thumb_compare::product-459295-017052ba-0797-4a04-9a21-f476a0dc5a89.jpg",
    "small": "https://dw95zbr0bn7mn.cloudfront.net/compare/asset/21816/small_compare::product-459295-017052ba-0797-4a04-9a21-f476a0dc5a89.jpg",
    "large": "https://dw95zbr0bn7mn.cloudfront.net/compare/asset/21816/large_compare::product-459295-017052ba-0797-4a04-9a21-f476a0dc5a89.jpg"
  },
  "varietal": {
    "id": 3,
    "name": "Blended Whisky",
    "displayName": "Blended Whisky"
  },
  "region": {
    "id": 8,
    "name": "Japanese Whisky",
    "displayName": "Japanese Whisky"
  },
  "tastingNotes": [],
  "reviews": [],
  "avgReviewScore": null
}

pricesCount returns as 7, as well as the low_price, average_price and high_price being different, so clearly some the filtering is working here.

We are querying index compare-product_searches_group_by_sizes and the query is in this Gist as query2.json.

Live Site

You can see the actual output of it here in the frootbat.com site.

https://frootbat.com/search/Suntory-Hibiki-Limited-17-Year-Old-Blended-Whisky-750/California,-United-States https://frootbat.com/product/459295/Suntory-Hibiki-Limited-Edition-17-Year-Old-Blended-Whisky-750ml-Bottle/California,-United-States

The search page shows a prices count of 11, whereas the product page has 7 prices, so first is not being filtered, second is.

{
"query": {
"function_score": {
"query": {
"bool": {
"must": [
{
"match": {
"product_keywords": {
"query": "'Suntory Hibiki Limited 17 Year Old Blended Whisky 750'",
"operator": "and",
"fuzziness": 1
}
}
}
],
"minimum_should_match": 1,
"should": [
{
"nested": {
"path": "stores",
"inner_hits": {
"size": 0
},
"query": {
"bool": {
"minimum_should_match": 1,
"should": [
{
"bool": {
"must": [
{
"term": {
"stores.type": 0
}
},
{
"geo_distance": {
"distance": "10km",
"stores.location": {
"lon": "-119.4179324",
"lat": "36.778261"
}
}
}
]
}
},
{
"bool": {
"must": [
{
"term": {
"stores.type": 1
}
},
{
"terms": {
"stores.id": [
237,
326,
416,
4,
103,
124,
336,
65,
76,
351,
425,
58,
237,
275,
9,
158,
299,
391,
409,
355,
316,
337,
381,
264,
216,
255,
60,
111,
184,
7,
75,
223,
227,
205,
285,
279,
418,
418,
285,
16,
425,
108,
337,
412,
361,
351,
293,
332,
1,
17,
17,
119,
147,
203,
98,
100,
72,
292,
112,
118,
308,
331,
334,
176,
201,
122,
66,
81,
361,
437,
449,
449,
449,
454,
457,
460,
461,
464,
471,
473,
488,
498,
181,
500,
504,
504,
505,
508,
508,
510,
516,
523,
529,
535,
535,
537,
540,
1055,
1060,
1076,
1094,
1098,
1109,
1110,
14,
15,
403,
100,
235,
371,
324,
326,
413,
176,
348,
383,
253,
16,
304,
313,
359,
65,
387,
411,
434,
387,
287,
180,
334,
260,
312,
355,
331,
437,
216,
262,
416,
38,
10,
17,
119,
176,
188,
88,
279,
195,
421,
251,
366,
197,
359,
242,
383,
104,
353,
128,
370,
258,
106,
62,
130,
159,
85,
353,
349,
102,
187,
312,
154,
434,
376,
222,
115,
114,
304,
446,
452,
454,
458,
464,
467,
473,
477,
485,
491,
494,
488,
490,
494,
253,
181,
385,
500,
505,
510,
510,
529,
533,
537,
539,
543,
544,
1064,
1064,
1076,
1092,
1094,
1100,
1105,
1110,
14,
1114,
1114,
38,
227,
106,
213,
216,
340,
340,
255,
275,
15,
420,
68,
122,
423,
359,
355,
270,
229,
427,
292,
336,
96,
391,
310,
252,
421,
90,
378,
141,
81,
351,
2,
3,
6,
381,
9,
90,
112,
180,
191,
272,
273,
90,
130,
155,
113,
207,
282,
231,
405,
118,
177,
188,
268,
359,
440,
444,
446,
448,
451,
451,
454,
460,
464,
466,
473,
488,
490,
490,
498,
494,
496,
501,
514,
518,
529,
530,
544,
1056,
1064,
1066,
1070,
1074,
1086,
1088,
1090,
1102,
1105,
1105,
1106,
1106,
1109,
1109,
1114,
54,
1088,
430,
54,
98,
110,
190,
420,
349,
9,
222,
373,
370,
375,
403,
416,
13,
4,
310,
379,
340,
415,
85,
220,
252,
233,
357,
367,
285,
289,
319,
420,
312,
141,
180,
256,
258,
262,
282,
104,
142,
361,
415,
147,
237,
317,
252,
280,
1,
353,
184,
300,
344,
405,
448,
467,
467,
181,
505,
531,
541,
544,
1057,
1060,
1062,
1066,
1074,
1080,
1080,
1082,
1084,
1084,
1088,
1098,
14,
323,
84,
93,
94,
70,
255,
297,
256,
185,
201,
231,
435,
284,
147,
378,
415,
389,
15,
289,
197,
409,
127,
106,
295,
391,
4,
184,
203,
413,
163,
187,
197,
302,
13,
66,
248,
366,
262,
389,
401,
418,
223,
289,
54,
98,
413,
5,
8,
81,
104,
38,
282,
297,
304,
207,
132,
342,
99,
275,
16,
421,
427,
293,
321,
223,
300,
334,
336,
428,
5,
222,
292,
331,
425,
444,
452,
460,
466,
471,
471,
478,
484,
478,
482,
484,
491,
253,
385,
504,
508,
514,
522,
526,
535,
1066,
1071,
1078,
1078,
1076,
1086,
1090,
1100,
1102,
1112
]
}
}
]
}
},
{
"bool": {
"must": [
{
"term": {
"stores.type": 1
}
},
{
"term": {
"stores.global_delivery": 1
}
}
]
}
}
]
}
}
}
}
],
"filter": {}
}
},
"script_score": {
"script": "_score + doc['product_relevancy_score'].value"
}
}
},
"sort": [
{
"_score": "desc"
},
{
"stores.amount": {
"mode": "min",
"order": "desc",
"nested_path": "stores",
"nested_filter": {
"bool": {
"minimum_should_match": 1,
"should": [
{
"bool": {
"must": [
{
"term": {
"stores.type": 0
}
},
{
"geo_distance": {
"distance": "10km",
"stores.location": {
"lon": "-119.4179324",
"lat": "36.778261"
}
}
}
]
}
},
{
"bool": {
"must": [
{
"term": {
"stores.type": 1
}
},
{
"terms": {
"stores.id": [
237,
326,
416,
4,
103,
124,
336,
65,
76,
351,
425,
58,
237,
275,
9,
158,
299,
391,
409,
355,
316,
337,
381,
264,
216,
255,
60,
111,
184,
7,
75,
223,
227,
205,
285,
279,
418,
418,
285,
16,
425,
108,
337,
412,
361,
351,
293,
332,
1,
17,
17,
119,
147,
203,
98,
100,
72,
292,
112,
118,
308,
331,
334,
176,
201,
122,
66,
81,
361,
437,
449,
449,
449,
454,
457,
460,
461,
464,
471,
473,
488,
498,
181,
500,
504,
504,
505,
508,
508,
510,
516,
523,
529,
535,
535,
537,
540,
1055,
1060,
1076,
1094,
1098,
1109,
1110,
14,
15,
403,
100,
235,
371,
324,
326,
413,
176,
348,
383,
253,
16,
304,
313,
359,
65,
387,
411,
434,
387,
287,
180,
334,
260,
312,
355,
331,
437,
216,
262,
416,
38,
10,
17,
119,
176,
188,
88,
279,
195,
421,
251,
366,
197,
359,
242,
383,
104,
353,
128,
370,
258,
106,
62,
130,
159,
85,
353,
349,
102,
187,
312,
154,
434,
376,
222,
115,
114,
304,
446,
452,
454,
458,
464,
467,
473,
477,
485,
491,
494,
488,
490,
494,
253,
181,
385,
500,
505,
510,
510,
529,
533,
537,
539,
543,
544,
1064,
1064,
1076,
1092,
1094,
1100,
1105,
1110,
14,
1114,
1114,
38,
227,
106,
213,
216,
340,
340,
255,
275,
15,
420,
68,
122,
423,
359,
355,
270,
229,
427,
292,
336,
96,
391,
310,
252,
421,
90,
378,
141,
81,
351,
2,
3,
6,
381,
9,
90,
112,
180,
191,
272,
273,
90,
130,
155,
113,
207,
282,
231,
405,
118,
177,
188,
268,
359,
440,
444,
446,
448,
451,
451,
454,
460,
464,
466,
473,
488,
490,
490,
498,
494,
496,
501,
514,
518,
529,
530,
544,
1056,
1064,
1066,
1070,
1074,
1086,
1088,
1090,
1102,
1105,
1105,
1106,
1106,
1109,
1109,
1114,
54,
1088,
430,
54,
98,
110,
190,
420,
349,
9,
222,
373,
370,
375,
403,
416,
13,
4,
310,
379,
340,
415,
85,
220,
252,
233,
357,
367,
285,
289,
319,
420,
312,
141,
180,
256,
258,
262,
282,
104,
142,
361,
415,
147,
237,
317,
252,
280,
1,
353,
184,
300,
344,
405,
448,
467,
467,
181,
505,
531,
541,
544,
1057,
1060,
1062,
1066,
1074,
1080,
1080,
1082,
1084,
1084,
1088,
1098,
14,
323,
84,
93,
94,
70,
255,
297,
256,
185,
201,
231,
435,
284,
147,
378,
415,
389,
15,
289,
197,
409,
127,
106,
295,
391,
4,
184,
203,
413,
163,
187,
197,
302,
13,
66,
248,
366,
262,
389,
401,
418,
223,
289,
54,
98,
413,
5,
8,
81,
104,
38,
282,
297,
304,
207,
132,
342,
99,
275,
16,
421,
427,
293,
321,
223,
300,
334,
336,
428,
5,
222,
292,
331,
425,
444,
452,
460,
466,
471,
471,
478,
484,
478,
482,
484,
491,
253,
385,
504,
508,
514,
522,
526,
535,
1066,
1071,
1078,
1078,
1076,
1086,
1090,
1100,
1102,
1112
]
}
}
]
}
},
{
"bool": {
"must": [
{
"term": {
"stores.type": 1
}
},
{
"term": {
"stores.global_delivery": 1
}
}
]
}
}
]
}
}
}
},
{
"stores.amount": {
"mode": "avg",
"order": "desc",
"nested_path": "stores",
"nested_filter": {
"bool": {
"minimum_should_match": 1,
"should": [
{
"bool": {
"must": [
{
"term": {
"stores.type": 0
}
},
{
"geo_distance": {
"distance": "10km",
"stores.location": {
"lon": "-119.4179324",
"lat": "36.778261"
}
}
}
]
}
},
{
"bool": {
"must": [
{
"term": {
"stores.type": 1
}
},
{
"terms": {
"stores.id": [
237,
326,
416,
4,
103,
124,
336,
65,
76,
351,
425,
58,
237,
275,
9,
158,
299,
391,
409,
355,
316,
337,
381,
264,
216,
255,
60,
111,
184,
7,
75,
223,
227,
205,
285,
279,
418,
418,
285,
16,
425,
108,
337,
412,
361,
351,
293,
332,
1,
17,
17,
119,
147,
203,
98,
100,
72,
292,
112,
118,
308,
331,
334,
176,
201,
122,
66,
81,
361,
437,
449,
449,
449,
454,
457,
460,
461,
464,
471,
473,
488,
498,
181,
500,
504,
504,
505,
508,
508,
510,
516,
523,
529,
535,
535,
537,
540,
1055,
1060,
1076,
1094,
1098,
1109,
1110,
14,
15,
403,
100,
235,
371,
324,
326,
413,
176,
348,
383,
253,
16,
304,
313,
359,
65,
387,
411,
434,
387,
287,
180,
334,
260,
312,
355,
331,
437,
216,
262,
416,
38,
10,
17,
119,
176,
188,
88,
279,
195,
421,
251,
366,
197,
359,
242,
383,
104,
353,
128,
370,
258,
106,
62,
130,
159,
85,
353,
349,
102,
187,
312,
154,
434,
376,
222,
115,
114,
304,
446,
452,
454,
458,
464,
467,
473,
477,
485,
491,
494,
488,
490,
494,
253,
181,
385,
500,
505,
510,
510,
529,
533,
537,
539,
543,
544,
1064,
1064,
1076,
1092,
1094,
1100,
1105,
1110,
14,
1114,
1114,
38,
227,
106,
213,
216,
340,
340,
255,
275,
15,
420,
68,
122,
423,
359,
355,
270,
229,
427,
292,
336,
96,
391,
310,
252,
421,
90,
378,
141,
81,
351,
2,
3,
6,
381,
9,
90,
112,
180,
191,
272,
273,
90,
130,
155,
113,
207,
282,
231,
405,
118,
177,
188,
268,
359,
440,
444,
446,
448,
451,
451,
454,
460,
464,
466,
473,
488,
490,
490,
498,
494,
496,
501,
514,
518,
529,
530,
544,
1056,
1064,
1066,
1070,
1074,
1086,
1088,
1090,
1102,
1105,
1105,
1106,
1106,
1109,
1109,
1114,
54,
1088,
430,
54,
98,
110,
190,
420,
349,
9,
222,
373,
370,
375,
403,
416,
13,
4,
310,
379,
340,
415,
85,
220,
252,
233,
357,
367,
285,
289,
319,
420,
312,
141,
180,
256,
258,
262,
282,
104,
142,
361,
415,
147,
237,
317,
252,
280,
1,
353,
184,
300,
344,
405,
448,
467,
467,
181,
505,
531,
541,
544,
1057,
1060,
1062,
1066,
1074,
1080,
1080,
1082,
1084,
1084,
1088,
1098,
14,
323,
84,
93,
94,
70,
255,
297,
256,
185,
201,
231,
435,
284,
147,
378,
415,
389,
15,
289,
197,
409,
127,
106,
295,
391,
4,
184,
203,
413,
163,
187,
197,
302,
13,
66,
248,
366,
262,
389,
401,
418,
223,
289,
54,
98,
413,
5,
8,
81,
104,
38,
282,
297,
304,
207,
132,
342,
99,
275,
16,
421,
427,
293,
321,
223,
300,
334,
336,
428,
5,
222,
292,
331,
425,
444,
452,
460,
466,
471,
471,
478,
484,
478,
482,
484,
491,
253,
385,
504,
508,
514,
522,
526,
535,
1066,
1071,
1078,
1078,
1076,
1086,
1090,
1100,
1102,
1112
]
}
}
]
}
},
{
"bool": {
"must": [
{
"term": {
"stores.type": 1
}
},
{
"term": {
"stores.global_delivery": 1
}
}
]
}
}
]
}
}
}
},
{
"stores.amount": {
"mode": "max",
"order": "desc",
"nested_path": "stores",
"nested_filter": {
"bool": {
"minimum_should_match": 1,
"should": [
{
"bool": {
"must": [
{
"term": {
"stores.type": 0
}
},
{
"geo_distance": {
"distance": "10km",
"stores.location": {
"lon": "-119.4179324",
"lat": "36.778261"
}
}
}
]
}
},
{
"bool": {
"must": [
{
"term": {
"stores.type": 1
}
},
{
"terms": {
"stores.id": [
237,
326,
416,
4,
103,
124,
336,
65,
76,
351,
425,
58,
237,
275,
9,
158,
299,
391,
409,
355,
316,
337,
381,
264,
216,
255,
60,
111,
184,
7,
75,
223,
227,
205,
285,
279,
418,
418,
285,
16,
425,
108,
337,
412,
361,
351,
293,
332,
1,
17,
17,
119,
147,
203,
98,
100,
72,
292,
112,
118,
308,
331,
334,
176,
201,
122,
66,
81,
361,
437,
449,
449,
449,
454,
457,
460,
461,
464,
471,
473,
488,
498,
181,
500,
504,
504,
505,
508,
508,
510,
516,
523,
529,
535,
535,
537,
540,
1055,
1060,
1076,
1094,
1098,
1109,
1110,
14,
15,
403,
100,
235,
371,
324,
326,
413,
176,
348,
383,
253,
16,
304,
313,
359,
65,
387,
411,
434,
387,
287,
180,
334,
260,
312,
355,
331,
437,
216,
262,
416,
38,
10,
17,
119,
176,
188,
88,
279,
195,
421,
251,
366,
197,
359,
242,
383,
104,
353,
128,
370,
258,
106,
62,
130,
159,
85,
353,
349,
102,
187,
312,
154,
434,
376,
222,
115,
114,
304,
446,
452,
454,
458,
464,
467,
473,
477,
485,
491,
494,
488,
490,
494,
253,
181,
385,
500,
505,
510,
510,
529,
533,
537,
539,
543,
544,
1064,
1064,
1076,
1092,
1094,
1100,
1105,
1110,
14,
1114,
1114,
38,
227,
106,
213,
216,
340,
340,
255,
275,
15,
420,
68,
122,
423,
359,
355,
270,
229,
427,
292,
336,
96,
391,
310,
252,
421,
90,
378,
141,
81,
351,
2,
3,
6,
381,
9,
90,
112,
180,
191,
272,
273,
90,
130,
155,
113,
207,
282,
231,
405,
118,
177,
188,
268,
359,
440,
444,
446,
448,
451,
451,
454,
460,
464,
466,
473,
488,
490,
490,
498,
494,
496,
501,
514,
518,
529,
530,
544,
1056,
1064,
1066,
1070,
1074,
1086,
1088,
1090,
1102,
1105,
1105,
1106,
1106,
1109,
1109,
1114,
54,
1088,
430,
54,
98,
110,
190,
420,
349,
9,
222,
373,
370,
375,
403,
416,
13,
4,
310,
379,
340,
415,
85,
220,
252,
233,
357,
367,
285,
289,
319,
420,
312,
141,
180,
256,
258,
262,
282,
104,
142,
361,
415,
147,
237,
317,
252,
280,
1,
353,
184,
300,
344,
405,
448,
467,
467,
181,
505,
531,
541,
544,
1057,
1060,
1062,
1066,
1074,
1080,
1080,
1082,
1084,
1084,
1088,
1098,
14,
323,
84,
93,
94,
70,
255,
297,
256,
185,
201,
231,
435,
284,
147,
378,
415,
389,
15,
289,
197,
409,
127,
106,
295,
391,
4,
184,
203,
413,
163,
187,
197,
302,
13,
66,
248,
366,
262,
389,
401,
418,
223,
289,
54,
98,
413,
5,
8,
81,
104,
38,
282,
297,
304,
207,
132,
342,
99,
275,
16,
421,
427,
293,
321,
223,
300,
334,
336,
428,
5,
222,
292,
331,
425,
444,
452,
460,
466,
471,
471,
478,
484,
478,
482,
484,
491,
253,
385,
504,
508,
514,
522,
526,
535,
1066,
1071,
1078,
1078,
1076,
1086,
1090,
1100,
1102,
1112
]
}
}
]
}
},
{
"bool": {
"must": [
{
"term": {
"stores.type": 1
}
},
{
"term": {
"stores.global_delivery": 1
}
}
]
}
}
]
}
}
}
}
],
"aggs": {
"product_container": {
"terms": {
"field": "product_container.keyword",
"size": 10000
}
},
"product_type_name": {
"terms": {
"field": "product_type_name.keyword",
"size": 10000
}
},
"product_country": {
"terms": {
"field": "product_country.keyword",
"size": 10000
}
},
"product_years": {
"terms": {
"field": "product_years.keyword",
"size": 10000
}
},
"product_packaging": {
"terms": {
"field": "product_packaging.keyword",
"size": 10000
}
}
}
}
{
"sort": [
{
"_score": "desc"
},
{
"stores.amount": {
"mode": "min",
"order": "desc",
"nested_path": "stores",
"nested_filter": {
"bool": {
"minimum_should_match": 1,
"should": [
{
"bool": {
"must": [
{
"term": {
"stores.type": 0
}
},
{
"geo_distance": {
"distance": "10km",
"stores.location": {
"lon": "-122.1180201",
"lat": "37.8857582"
}
}
}
]
}
},
{
"bool": {
"must": [
{
"term": {
"stores.type": 1
}
},
{
"terms": {
"stores.id": [
326,
416,
65,
425,
237,
275,
391,
409,
355,
216,
255,
184,
227,
337,
119,
203,
292,
118,
176,
201,
122,
437,
449,
464,
488,
500,
504,
508,
510,
537,
1060,
1094,
1110,
14,
15,
324,
413,
16,
359,
387,
434,
334,
262,
38,
17,
279,
366,
383,
353,
370,
258,
102,
312,
304,
452,
494,
490,
253,
385,
529,
539,
1064,
106,
340,
427,
141,
81,
351,
381,
9,
90,
180,
130,
405,
454,
460,
466,
473,
498,
514,
1066,
1090,
1102,
1105,
1106,
1109,
1114,
1088,
98,
349,
403,
13,
310,
252,
285,
420,
256,
104,
361,
415,
1,
467,
181,
505,
544,
1080,
1084,
1098,
297,
147,
378,
389,
289,
127,
4,
197,
66,
418,
223,
54,
5,
282,
421,
293,
300,
336,
222,
331,
444,
471,
484,
491,
535,
1078,
1076,
1086,
1100
]
}
}
]
}
},
{
"bool": {
"must": [
{
"term": {
"stores.type": 1
}
},
{
"term": {
"stores.global_delivery": 1
}
}
]
}
}
]
}
}
}
},
{
"stores.amount": {
"mode": "avg",
"order": "desc",
"nested_path": "stores",
"nested_filter": {
"bool": {
"minimum_should_match": 1,
"should": [
{
"bool": {
"must": [
{
"term": {
"stores.type": 0
}
},
{
"geo_distance": {
"distance": "10km",
"stores.location": {
"lon": "-122.1180201",
"lat": "37.8857582"
}
}
}
]
}
},
{
"bool": {
"must": [
{
"term": {
"stores.type": 1
}
},
{
"terms": {
"stores.id": [
326,
416,
65,
425,
237,
275,
391,
409,
355,
216,
255,
184,
227,
337,
119,
203,
292,
118,
176,
201,
122,
437,
449,
464,
488,
500,
504,
508,
510,
537,
1060,
1094,
1110,
14,
15,
324,
413,
16,
359,
387,
434,
334,
262,
38,
17,
279,
366,
383,
353,
370,
258,
102,
312,
304,
452,
494,
490,
253,
385,
529,
539,
1064,
106,
340,
427,
141,
81,
351,
381,
9,
90,
180,
130,
405,
454,
460,
466,
473,
498,
514,
1066,
1090,
1102,
1105,
1106,
1109,
1114,
1088,
98,
349,
403,
13,
310,
252,
285,
420,
256,
104,
361,
415,
1,
467,
181,
505,
544,
1080,
1084,
1098,
297,
147,
378,
389,
289,
127,
4,
197,
66,
418,
223,
54,
5,
282,
421,
293,
300,
336,
222,
331,
444,
471,
484,
491,
535,
1078,
1076,
1086,
1100
]
}
}
]
}
},
{
"bool": {
"must": [
{
"term": {
"stores.type": 1
}
},
{
"term": {
"stores.global_delivery": 1
}
}
]
}
}
]
}
}
}
},
{
"stores.amount": {
"mode": "max",
"order": "desc",
"nested_path": "stores",
"nested_filter": {
"bool": {
"minimum_should_match": 1,
"should": [
{
"bool": {
"must": [
{
"term": {
"stores.type": 0
}
},
{
"geo_distance": {
"distance": "10km",
"stores.location": {
"lon": "-122.1180201",
"lat": "37.8857582"
}
}
}
]
}
},
{
"bool": {
"must": [
{
"term": {
"stores.type": 1
}
},
{
"terms": {
"stores.id": [
326,
416,
65,
425,
237,
275,
391,
409,
355,
216,
255,
184,
227,
337,
119,
203,
292,
118,
176,
201,
122,
437,
449,
464,
488,
500,
504,
508,
510,
537,
1060,
1094,
1110,
14,
15,
324,
413,
16,
359,
387,
434,
334,
262,
38,
17,
279,
366,
383,
353,
370,
258,
102,
312,
304,
452,
494,
490,
253,
385,
529,
539,
1064,
106,
340,
427,
141,
81,
351,
381,
9,
90,
180,
130,
405,
454,
460,
466,
473,
498,
514,
1066,
1090,
1102,
1105,
1106,
1109,
1114,
1088,
98,
349,
403,
13,
310,
252,
285,
420,
256,
104,
361,
415,
1,
467,
181,
505,
544,
1080,
1084,
1098,
297,
147,
378,
389,
289,
127,
4,
197,
66,
418,
223,
54,
5,
282,
421,
293,
300,
336,
222,
331,
444,
471,
484,
491,
535,
1078,
1076,
1086,
1100
]
}
}
]
}
},
{
"bool": {
"must": [
{
"term": {
"stores.type": 1
}
},
{
"term": {
"stores.global_delivery": 1
}
}
]
}
}
]
}
}
}
}
],
"query": {
"bool": {
"must": [
{
"match": {
"id": 459295
}
}
],
"minimum_should_match": 1,
"should": [
{
"nested": {
"path": "stores",
"inner_hits": {
"size": 0
},
"query": {
"bool": {
"minimum_should_match": 1,
"should": [
{
"bool": {
"must": [
{
"term": {
"stores.type": 0
}
},
{
"geo_distance": {
"distance": "10km",
"stores.location": {
"lon": "-122.1180201",
"lat": "37.8857582"
}
}
}
]
}
},
{
"bool": {
"must": [
{
"term": {
"stores.type": 1
}
},
{
"terms": {
"stores.id": [
326,
416,
65,
425,
237,
275,
391,
409,
355,
216,
255,
184,
227,
337,
119,
203,
292,
118,
176,
201,
122,
437,
449,
464,
488,
500,
504,
508,
510,
537,
1060,
1094,
1110,
14,
15,
324,
413,
16,
359,
387,
434,
334,
262,
38,
17,
279,
366,
383,
353,
370,
258,
102,
312,
304,
452,
494,
490,
253,
385,
529,
539,
1064,
106,
340,
427,
141,
81,
351,
381,
9,
90,
180,
130,
405,
454,
460,
466,
473,
498,
514,
1066,
1090,
1102,
1105,
1106,
1109,
1114,
1088,
98,
349,
403,
13,
310,
252,
285,
420,
256,
104,
361,
415,
1,
467,
181,
505,
544,
1080,
1084,
1098,
297,
147,
378,
389,
289,
127,
4,
197,
66,
418,
223,
54,
5,
282,
421,
293,
300,
336,
222,
331,
444,
471,
484,
491,
535,
1078,
1076,
1086,
1100
]
}
}
]
}
},
{
"bool": {
"must": [
{
"term": {
"stores.type": 1
}
},
{
"term": {
"stores.global_delivery": 1
}
}
]
}
}
]
}
}
}
}
]
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment