def exists(self, field: str, must: bool = True) -> None: """ Add exists query https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-exists-query.html """ if must: if self._query.empty(): self._query = NotNull(field) else: self._query = self._query & NotNull(field) else: if self._query.empty(): self._query = IsNull(field) else: self._query = self._query & IsNull(field)
def test_leaf_boolean_filter(self): assert GreaterEqual("a", 2).build() == {"range": {"a": {"gte": 2}}} assert LessEqual("a", 2).build() == {"range": {"a": {"lte": 2}}} assert Less("a", 2).build() == {"range": {"a": {"lt": 2}}} assert Equal("a", 2).build() == {"term": {"a": 2}} exp = Equal("a", 2) assert (~exp).build()["bool"], {"must_not": {"term": {"a": 2}}} assert Greater("a", 2).build() == {"range": {"a": {"gt": 2}}} assert IsIn("a", [1, 2, 3]).build() == {"terms": {"a": [1, 2, 3]}} assert Like("a", "a*b").build() == {"wildcard": {"a": "a*b"}} assert Rlike("a", "a*b").build() == {"regexp": {"a": "a*b"}} assert Startswith("a", "jj").build() == {"prefix": {"a": "jj"}} assert IsNull("a").build() == {"missing": {"field": "a"}} assert NotNull("a").build() == {"exists": {"field": "a"}} assert ScriptFilter( 'doc["num1"].value > params.param1', lang="painless", params={"param1": 5} ).build() == { "script": { "script": { "lang": "painless", "source": 'doc["num1"].value > params.param1', "params": {"param1": 5}, } } } assert IsIn("ids", [1, 2, 3]).build() == {"ids": {"values": [1, 2, 3]}}
def notna(self) -> BooleanFilter: """ Detect existing (non-missing) values. Returns ------- eland.Series Mask of bool values for each element in Series that indicates whether an element is not an NA value See Also -------- :pandas_api_docs:`pandas.Series.notna` """ return NotNull(field=self.name)