Skip to content

Commit 28a82a0

Browse files
authored
Add body fields to scroll and search_mvt
1 parent 2cd20f8 commit 28a82a0

File tree

12 files changed

+271
-96
lines changed

12 files changed

+271
-96
lines changed

elasticsearch/_async/client/__init__.py

Lines changed: 75 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ async def bulk(self, body, index=None, doc_type=None, params=None, headers=None)
469469
body=body,
470470
)
471471

472-
@query_params()
472+
@query_params(body_params=["scroll_id"])
473473
async def clear_scroll(self, body=None, scroll_id=None, params=None, headers=None):
474474
"""
475475
Explicitly clears the search context for a scroll.
@@ -481,7 +481,7 @@ async def clear_scroll(self, body=None, scroll_id=None, params=None, headers=Non
481481
:arg scroll_id: A comma-separated list of scroll IDs to clear
482482
"""
483483
if scroll_id in SKIP_IN_PATH and body in SKIP_IN_PATH:
484-
raise ValueError("You need to supply scroll_id or body.")
484+
raise ValueError("Empty value passed for a required argument 'scroll_id'.")
485485
elif scroll_id and not body:
486486
body = {"scroll_id": [scroll_id]}
487487
elif scroll_id:
@@ -1496,7 +1496,12 @@ async def scripts_painless_execute(self, body=None, params=None, headers=None):
14961496
body=body,
14971497
)
14981498

1499-
@query_params("rest_total_hits_as_int", "scroll")
1499+
@query_params(
1500+
"rest_total_hits_as_int",
1501+
"scroll",
1502+
"scroll_id",
1503+
body_params=["scroll", "scroll_id"],
1504+
)
15001505
async def scroll(self, body=None, scroll_id=None, params=None, headers=None):
15011506
"""
15021507
Allows to retrieve a large numbers of results from a single search request.
@@ -1506,13 +1511,13 @@ async def scroll(self, body=None, scroll_id=None, params=None, headers=None):
15061511
:arg body: The scroll ID if not passed by URL or query
15071512
parameter.
15081513
:arg scroll_id: The scroll ID
1509-
:arg rest_total_hits_as_int: Indicates whether hits.total should
1510-
be rendered as an integer or an object in the rest search response
1511-
:arg scroll: Specify how long a consistent view of the index
1512-
should be maintained for scrolled search
1514+
:arg rest_total_hits_as_int: If true, the API response’s
1515+
hit.total property is returned as an integer. If false, the API
1516+
response’s hit.total property is returned as an object.
1517+
:arg scroll: Period to retain the search context for scrolling.
15131518
"""
15141519
if scroll_id in SKIP_IN_PATH and body in SKIP_IN_PATH:
1515-
raise ValueError("You need to supply scroll_id or body.")
1520+
raise ValueError("Empty value passed for a required argument 'scroll_id'.")
15161521
elif scroll_id and not body:
15171522
body = {"scroll_id": scroll_id}
15181523
elif scroll_id:
@@ -2297,7 +2302,25 @@ async def terms_enum(self, index, body=None, params=None, headers=None):
22972302
body=body,
22982303
)
22992304

2300-
@query_params("exact_bounds", "extent", "grid_precision", "grid_type", "size")
2305+
@query_params(
2306+
"exact_bounds",
2307+
"extent",
2308+
"grid_precision",
2309+
"grid_type",
2310+
"size",
2311+
body_params=[
2312+
"aggs",
2313+
"exact_bounds",
2314+
"extent",
2315+
"fields",
2316+
"grid_precision",
2317+
"grid_type",
2318+
"query",
2319+
"runtime_mappings",
2320+
"size",
2321+
"sort",
2322+
],
2323+
)
23012324
async def search_mvt(
23022325
self, index, field, zoom, x, y, body=None, params=None, headers=None
23032326
):
@@ -2319,17 +2342,52 @@ async def search_mvt(
23192342
:arg x: X coordinate for the vector tile to search
23202343
:arg y: Y coordinate for the vector tile to search
23212344
:arg body: Search request body.
2322-
:arg exact_bounds: If false, the meta layer's feature is the
2323-
bounding box of the tile. If true, the meta layer's feature is a
2324-
bounding box resulting from a `geo_bounds` aggregation.
2325-
:arg extent: Size, in pixels, of a side of the vector tile.
2326-
Default: 4096
2345+
:arg aggs: Sub-aggregations for the geotile_grid.
2346+
2347+
Supports the following aggregation types:
2348+
- avg
2349+
- cardinality
2350+
- max
2351+
- min
2352+
- sum
2353+
:arg exact_bounds: If false, the meta layer’s feature is the
2354+
bounding box of the tile.
2355+
If true, the meta layer’s feature is a bounding box resulting from a
2356+
geo_bounds aggregation. The aggregation runs on <field> values that
2357+
intersect
2358+
the <zoom>/<x>/<y> tile with wrap_longitude set to false. The resulting
2359+
bounding box may be larger than the vector tile.
2360+
:arg extent: Size, in pixels, of a side of the tile. Vector
2361+
tiles are square with equal sides.
2362+
:arg fields: Fields to return in the `hits` layer. Supports
2363+
wildcards (`*`).
2364+
This parameter does not support fields with array values. Fields with
2365+
array
2366+
values may return inconsistent results.
23272367
:arg grid_precision: Additional zoom levels available through
2328-
the aggs layer. Accepts 0-8. Default: 8
2368+
the aggs layer. For example, if <zoom> is 7
2369+
and grid_precision is 8, you can zoom in up to level 15. Accepts 0-8. If
2370+
0, results
2371+
don’t include the aggs layer.
23292372
:arg grid_type: Determines the geometry type for features in the
2330-
aggs layer. Valid choices: grid, point Default: grid
2373+
aggs layer. In the aggs layer,
2374+
each feature represents a geotile_grid cell. If 'grid' each feature is a
2375+
Polygon
2376+
of the cells bounding box. If 'point' each feature is a Point that is
2377+
the centroid
2378+
of the cell.
2379+
:arg query: Query DSL used to filter documents for the search.
2380+
:arg runtime_mappings: Defines one or more runtime fields in the
2381+
search request. These fields take
2382+
precedence over mapped fields with the same name.
23312383
:arg size: Maximum number of features to return in the hits
2332-
layer. Accepts 0-10000. Default: 10000
2384+
layer. Accepts 0-10000.
2385+
If 0, results don’t include the hits layer.
2386+
:arg sort: Sorts features in the hits layer. By default, the API
2387+
calculates a bounding
2388+
box for each feature. It sorts features based on this box’s diagonal
2389+
length,
2390+
from longest to shortest.
23332391
"""
23342392
for param in (index, field, zoom, x, y):
23352393
if param in SKIP_IN_PATH:

elasticsearch/_async/client/__init__.pyi

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -244,8 +244,8 @@ class AsyncElasticsearch(object):
244244
async def clear_scroll(
245245
self,
246246
*,
247-
body: Optional[Union[Mapping[str, Any], str]] = ...,
248-
scroll_id: Optional[Any] = ...,
247+
body: Optional[Mapping[str, Any]] = ...,
248+
scroll_id: Optional[Union[List[str], str]] = ...,
249249
pretty: Optional[bool] = ...,
250250
human: Optional[bool] = ...,
251251
error_trace: Optional[bool] = ...,
@@ -834,9 +834,9 @@ class AsyncElasticsearch(object):
834834
self,
835835
*,
836836
body: Optional[Mapping[str, Any]] = ...,
837-
scroll_id: Optional[Any] = ...,
838837
rest_total_hits_as_int: Optional[bool] = ...,
839-
scroll: Optional[Any] = ...,
838+
scroll: Optional[Union[int, str]] = ...,
839+
scroll_id: Optional[str] = ...,
840840
pretty: Optional[bool] = ...,
841841
human: Optional[bool] = ...,
842842
error_trace: Optional[bool] = ...,
@@ -1229,17 +1229,35 @@ class AsyncElasticsearch(object):
12291229
async def search_mvt(
12301230
self,
12311231
*,
1232-
index: Any,
1233-
field: Any,
1234-
zoom: Any,
1235-
x: Any,
1236-
y: Any,
1232+
index: Union[List[str], str],
1233+
field: str,
1234+
zoom: int,
1235+
x: int,
1236+
y: int,
12371237
body: Optional[Mapping[str, Any]] = ...,
1238+
aggs: Optional[Mapping[str, Mapping[str, Any]]] = ...,
12381239
exact_bounds: Optional[bool] = ...,
1239-
extent: Optional[Any] = ...,
1240-
grid_precision: Optional[Any] = ...,
1241-
grid_type: Optional[Any] = ...,
1242-
size: Optional[Any] = ...,
1240+
extent: Optional[int] = ...,
1241+
fields: Optional[Union[List[str], str]] = ...,
1242+
grid_precision: Optional[int] = ...,
1243+
grid_type: Optional[Union[Literal["grid", "point"], str]] = ...,
1244+
query: Optional[Mapping[str, Any]] = ...,
1245+
runtime_mappings: Optional[Mapping[str, Mapping[str, Any]]] = ...,
1246+
size: Optional[int] = ...,
1247+
sort: Optional[
1248+
Union[
1249+
List[
1250+
Union[
1251+
Mapping[str, Any],
1252+
Union[Literal["asc", "desc", "_doc"], str],
1253+
str,
1254+
]
1255+
],
1256+
Union[
1257+
Mapping[str, Any], Union[Literal["asc", "desc", "_doc"], str], str
1258+
],
1259+
]
1260+
] = ...,
12431261
pretty: Optional[bool] = ...,
12441262
human: Optional[bool] = ...,
12451263
error_trace: Optional[bool] = ...,
@@ -1252,4 +1270,4 @@ class AsyncElasticsearch(object):
12521270
api_key: Optional[Union[str, Tuple[str, str]]] = ...,
12531271
params: Optional[MutableMapping[str, Any]] = ...,
12541272
headers: Optional[MutableMapping[str, str]] = ...,
1255-
) -> Union[Dict[str, Any], bytes]: ...
1273+
) -> bytes: ...

elasticsearch/_async/helpers.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ async def _process_bulk_chunk(
7171

7272
try:
7373
# send the actual request
74-
resp = await client.bulk("\n".join(bulk_actions) + "\n", *args, **kwargs)
74+
resp = await client.bulk(*args, body="\n".join(bulk_actions) + "\n", **kwargs)
7575
except TransportError as e:
7676
gen = _process_bulk_chunk_error(
7777
error=e,
@@ -391,14 +391,14 @@ async def async_scan(
391391
),
392392
)
393393
resp = await client.scroll(
394-
body={"scroll_id": scroll_id, "scroll": scroll}, **scroll_kwargs
394+
scroll_id=scroll_id, scroll=scroll, **scroll_kwargs
395395
)
396396
scroll_id = resp.get("_scroll_id")
397397

398398
finally:
399399
if scroll_id and clear_scroll:
400400
await client.clear_scroll(
401-
body={"scroll_id": [scroll_id]},
401+
scroll_id=scroll_id,
402402
**transport_kwargs,
403403
ignore=(404,),
404404
params={"__elastic_client_meta": (("h", "s"),)},

elasticsearch/client/__init__.py

Lines changed: 75 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ def bulk(self, body, index=None, doc_type=None, params=None, headers=None):
467467
body=body,
468468
)
469469

470-
@query_params()
470+
@query_params(body_params=["scroll_id"])
471471
def clear_scroll(self, body=None, scroll_id=None, params=None, headers=None):
472472
"""
473473
Explicitly clears the search context for a scroll.
@@ -479,7 +479,7 @@ def clear_scroll(self, body=None, scroll_id=None, params=None, headers=None):
479479
:arg scroll_id: A comma-separated list of scroll IDs to clear
480480
"""
481481
if scroll_id in SKIP_IN_PATH and body in SKIP_IN_PATH:
482-
raise ValueError("You need to supply scroll_id or body.")
482+
raise ValueError("Empty value passed for a required argument 'scroll_id'.")
483483
elif scroll_id and not body:
484484
body = {"scroll_id": [scroll_id]}
485485
elif scroll_id:
@@ -1486,7 +1486,12 @@ def scripts_painless_execute(self, body=None, params=None, headers=None):
14861486
body=body,
14871487
)
14881488

1489-
@query_params("rest_total_hits_as_int", "scroll")
1489+
@query_params(
1490+
"rest_total_hits_as_int",
1491+
"scroll",
1492+
"scroll_id",
1493+
body_params=["scroll", "scroll_id"],
1494+
)
14901495
def scroll(self, body=None, scroll_id=None, params=None, headers=None):
14911496
"""
14921497
Allows to retrieve a large numbers of results from a single search request.
@@ -1496,13 +1501,13 @@ def scroll(self, body=None, scroll_id=None, params=None, headers=None):
14961501
:arg body: The scroll ID if not passed by URL or query
14971502
parameter.
14981503
:arg scroll_id: The scroll ID
1499-
:arg rest_total_hits_as_int: Indicates whether hits.total should
1500-
be rendered as an integer or an object in the rest search response
1501-
:arg scroll: Specify how long a consistent view of the index
1502-
should be maintained for scrolled search
1504+
:arg rest_total_hits_as_int: If true, the API response’s
1505+
hit.total property is returned as an integer. If false, the API
1506+
response’s hit.total property is returned as an object.
1507+
:arg scroll: Period to retain the search context for scrolling.
15031508
"""
15041509
if scroll_id in SKIP_IN_PATH and body in SKIP_IN_PATH:
1505-
raise ValueError("You need to supply scroll_id or body.")
1510+
raise ValueError("Empty value passed for a required argument 'scroll_id'.")
15061511
elif scroll_id and not body:
15071512
body = {"scroll_id": scroll_id}
15081513
elif scroll_id:
@@ -2285,7 +2290,25 @@ def terms_enum(self, index, body=None, params=None, headers=None):
22852290
body=body,
22862291
)
22872292

2288-
@query_params("exact_bounds", "extent", "grid_precision", "grid_type", "size")
2293+
@query_params(
2294+
"exact_bounds",
2295+
"extent",
2296+
"grid_precision",
2297+
"grid_type",
2298+
"size",
2299+
body_params=[
2300+
"aggs",
2301+
"exact_bounds",
2302+
"extent",
2303+
"fields",
2304+
"grid_precision",
2305+
"grid_type",
2306+
"query",
2307+
"runtime_mappings",
2308+
"size",
2309+
"sort",
2310+
],
2311+
)
22892312
def search_mvt(
22902313
self, index, field, zoom, x, y, body=None, params=None, headers=None
22912314
):
@@ -2307,17 +2330,52 @@ def search_mvt(
23072330
:arg x: X coordinate for the vector tile to search
23082331
:arg y: Y coordinate for the vector tile to search
23092332
:arg body: Search request body.
2310-
:arg exact_bounds: If false, the meta layer's feature is the
2311-
bounding box of the tile. If true, the meta layer's feature is a
2312-
bounding box resulting from a `geo_bounds` aggregation.
2313-
:arg extent: Size, in pixels, of a side of the vector tile.
2314-
Default: 4096
2333+
:arg aggs: Sub-aggregations for the geotile_grid.
2334+
2335+
Supports the following aggregation types:
2336+
- avg
2337+
- cardinality
2338+
- max
2339+
- min
2340+
- sum
2341+
:arg exact_bounds: If false, the meta layer’s feature is the
2342+
bounding box of the tile.
2343+
If true, the meta layer’s feature is a bounding box resulting from a
2344+
geo_bounds aggregation. The aggregation runs on <field> values that
2345+
intersect
2346+
the <zoom>/<x>/<y> tile with wrap_longitude set to false. The resulting
2347+
bounding box may be larger than the vector tile.
2348+
:arg extent: Size, in pixels, of a side of the tile. Vector
2349+
tiles are square with equal sides.
2350+
:arg fields: Fields to return in the `hits` layer. Supports
2351+
wildcards (`*`).
2352+
This parameter does not support fields with array values. Fields with
2353+
array
2354+
values may return inconsistent results.
23152355
:arg grid_precision: Additional zoom levels available through
2316-
the aggs layer. Accepts 0-8. Default: 8
2356+
the aggs layer. For example, if <zoom> is 7
2357+
and grid_precision is 8, you can zoom in up to level 15. Accepts 0-8. If
2358+
0, results
2359+
don’t include the aggs layer.
23172360
:arg grid_type: Determines the geometry type for features in the
2318-
aggs layer. Valid choices: grid, point Default: grid
2361+
aggs layer. In the aggs layer,
2362+
each feature represents a geotile_grid cell. If 'grid' each feature is a
2363+
Polygon
2364+
of the cells bounding box. If 'point' each feature is a Point that is
2365+
the centroid
2366+
of the cell.
2367+
:arg query: Query DSL used to filter documents for the search.
2368+
:arg runtime_mappings: Defines one or more runtime fields in the
2369+
search request. These fields take
2370+
precedence over mapped fields with the same name.
23192371
:arg size: Maximum number of features to return in the hits
2320-
layer. Accepts 0-10000. Default: 10000
2372+
layer. Accepts 0-10000.
2373+
If 0, results don’t include the hits layer.
2374+
:arg sort: Sorts features in the hits layer. By default, the API
2375+
calculates a bounding
2376+
box for each feature. It sorts features based on this box’s diagonal
2377+
length,
2378+
from longest to shortest.
23212379
"""
23222380
for param in (index, field, zoom, x, y):
23232381
if param in SKIP_IN_PATH:

0 commit comments

Comments
 (0)