DataFrame.os_query
- DataFrame.os_query(query) DataFrame [source]
Applies an OpenSearch DSL query to the current DataFrame.
Parameters
- query:
Dictionary of the OpenSearch DSL query to apply
Returns
- opensearch_py_ml.DataFrame:
opensearch_py_ml DataFrame with the query applied
Examples
Apply a `geo-distance query`_ to a dataset with a geo-point column
geoip.location
.>>> from tests import OPENSEARCH_TEST_CLIENT
>>> df = oml.DataFrame(OPENSEARCH_TEST_CLIENT, 'ecommerce', columns=['customer_first_name', 'geoip.city_name']) >>> df.os_query({"bool": {"filter": {"geo_distance": {"distance": "1km", "geoip.location": [55.3, 25.3]}}}}).head() customer_first_name geoip.city_name 1 Mary Dubai 9 Rabbia Al Dubai 10 Rabbia Al Dubai 22 Mary Dubai 30 Robbie Dubai [5 rows x 2 columns]
If using an occurrence like
must
orfilter
you must nest it withinbool
:# Correct: df.os_query({ "bool": { "filter": {...} } }) # Incorrect, needs to be nested under 'bool': df.os_query({ "filter": {...} })