DataFrame.os_match

DataFrame.os_match(text: str, *, columns: str | Sequence[str] | None = None, match_phrase: bool = False, must_not_match: bool = False, multi_match_type: str | None = None, match_only_text_fields: bool = True, analyzer: str | None = None, fuzziness: int | str | None = None, **kwargs: Any) DataFrame[source]

Filters data with an OpenSearch match, match_phrase, or multi_match query depending on the given parameters and columns.

Read more about Full-Text Queries in OpenSearch

By default all fields of type ‘text’ within OpenSearch are queried otherwise specific columns can be specified via the columns parameter or a single column can be filtered on with opensearch_py_ml.Series.os_match()

All additional keyword arguments are passed in the body of the match query.

Parameters

text: str

String of text to search for

columns: str, List[str], optional

List of columns to search over. Defaults to all ‘text’ fields in OpenSearch

match_phrase: bool, default False

If True will use match_phrase instead of match query which takes into account the order of the text parameter.

must_not_match: bool, default False

If True will apply a boolean NOT (~) to the query. Instead of requiring a match the query will require text to not match.

multi_match_type: str, optional

If given and matching against multiple columns will set the multi_match.type setting

match_only_text_fields: bool, default True

When True this function will raise an error if any non-text fields are queried to prevent fields that aren’t analyzed from not working properly. Set to False to ignore this preventative check.

analyzer: str, optional

Specify which analyzer to use for the match query

fuzziness: int, str, optional

Specify the fuzziness option for the match query

Returns

DataFrame

A filtered opensearch_py_ml.DataFrame with the given match query

Examples

>>> from tests import OPENSEARCH_TEST_CLIENT
>>> df = oml.DataFrame(OPENSEARCH_TEST_CLIENT, "ecommerce")
>>> df.os_match("Men's", columns=["category"])
                                              category currency  ...   type     user
0                                     [Men's Clothing]      EUR  ...  order    eddie
4                  [Men's Clothing, Men's Accessories]      EUR  ...  order    eddie
6                                     [Men's Clothing]      EUR  ...  order   oliver
7     [Men's Clothing, Men's Accessories, Men's Shoes]      EUR  ...  order      abd
11                 [Men's Accessories, Men's Clothing]      EUR  ...  order    eddie
...                                                ...      ...  ...    ...      ...
4663                     [Men's Shoes, Men's Clothing]      EUR  ...  order    samir
4667                     [Men's Clothing, Men's Shoes]      EUR  ...  order   sultan
4671                                  [Men's Clothing]      EUR  ...  order      jim
4672                                  [Men's Clothing]      EUR  ...  order    yahya
4674             [Women's Accessories, Men's Clothing]      EUR  ...  order  jackson

[2310 rows x 45 columns]