WeaviateEx.Filter (WeaviateEx v0.7.4)
View SourceFilter system for building complex query filters.
Provides a fluent API for constructing filters with operators and combinators that can be converted to GraphQL format for Weaviate queries.
Examples
# Simple equality filter
Filter.equal("status", "published")
# Numeric comparison
Filter.greater_than("views", 100)
# Combining filters with AND
Filter.all_of([
Filter.equal("status", "published"),
Filter.greater_than("views", 100)
])
# Complex nested filters
Filter.all_of([
Filter.any_of([
Filter.equal("type", "article"),
Filter.equal("type", "post")
]),
Filter.greater_than("createdAt", "2024-01-01")
])
Summary
Functions
Combine filters with AND logic.
Combine filters with OR logic.
Filter by object creation time.
Create a filter by ID.
Create a filter by property with an operator.
Filter by property string or array length.
Create a filter by reference property.
Filter by reference count.
Create a filter for a multi-target reference property.
Create a filter using a reference path.
Filter by object update time.
Contains all operator (array subset)
Contains any operator (array intersection)
Contains none operator (array contains none of the values).
Equal operator
Greater than or equal operator
Greater than operator
Create a length path for a property.
Less than or equal operator
Less than operator
Like operator (wildcard matching)
Negate a filter.
Not equal operator
Null check operator
Convert a filter to GraphQL format.
Within geo range operator.
Types
Functions
Combine filters with AND logic.
All filters must match for the result to be included.
Examples
Filter.all_of([
Filter.equal("status", "published"),
Filter.greater_than("views", 100)
])
Combine filters with OR logic.
At least one filter must match for the result to be included.
Examples
Filter.any_of([
Filter.equal("status", "draft"),
Filter.equal("status", "published")
])
Filter by object creation time.
Examples
Filter.by_creation_time(:greater_than, "2024-01-01T00:00:00Z")
Create a filter by ID.
Examples
Filter.by_id(:equal, "00000000-0000-0000-0000-000000000001")
Create a filter by property with an operator.
Examples
Filter.by_property("status", :equal, "published")
Filter.by_property("views", :greater_than, 1000)
@spec by_property_length(String.t(), operator(), non_neg_integer()) :: filter()
Filter by property string or array length.
Use this to filter based on the length of text properties or the number of elements in array properties.
Arguments
property- Property nameoperator- Comparison operator::equal,:not_equal,:greater_than,:greater_or_equal,:less_than,:less_or_equalvalue- Length value (non-negative integer)
Examples
# Title must be at least 10 characters
Filter.by_property_length("title", :greater_or_equal, 10)
# Tags array must have exactly 3 elements
Filter.by_property_length("tags", :equal, 3)
# Content must be less than 5000 characters
Filter.by_property_length("content", :less_than, 5000)
Create a filter by reference property.
Examples
Filter.by_ref("hasAuthor", "Author", :equal, "John Doe")
Filter by reference count.
Examples
Filter.by_ref_count("hasAuthor", :greater_than, 0)
Create a filter for a multi-target reference property.
For reference properties that can point to multiple collections, this allows filtering by a specific target collection.
Arguments
property- Multi-target reference property nametarget_collection- Specific target collection to filtertarget_property- Property in the target collectionoperator- Filter operatorvalue- Filter value
Examples
Filter.by_ref_multi_target("relatedTo", "Article", "title", :equal, "Test")
Filter.by_ref_multi_target("mentions", "Person", "verified", :equal, true)
@spec by_ref_path(WeaviateEx.Filter.RefPath.t(), String.t(), operator(), value()) :: filter()
Create a filter using a reference path.
This is a convenience wrapper around WeaviateEx.Filter.RefPath.
Examples
alias WeaviateEx.Filter.RefPath
path = RefPath.through("hasAuthor", "Author")
Filter.by_ref_path(path, "name", :equal, "John")
Filter by object update time.
Examples
Filter.by_update_time(:greater_than, "2024-01-01T00:00:00Z")
Contains all operator (array subset)
Contains any operator (array intersection)
Contains none operator (array contains none of the values).
Examples
Filter.contains_none("tags", ["draft", "archived"])
Equal operator
Greater than or equal operator
Greater than operator
Create a length path for a property.
This wraps the property name in the len() function for length-based filtering.
Examples
Filter.len("description")
#=> "len(description)"
Less than or equal operator
Less than operator
Like operator (wildcard matching)
Negate a filter.
Examples
Filter.not_(Filter.equal("archived", true))
Not equal operator
Null check operator
Convert a filter to GraphQL format.
Examples
filter = Filter.equal("status", "published")
Filter.to_graphql(filter)
# => %{path: ["status"], operator: "Equal", valueText: "published"}
Within geo range operator.
Examples
Filter.within_geo_range("location", {40.7128, -74.0060}, 5000.0)