I’m trying to delete all elements that do not have a property, any ideas of doing that?
hi @Matheus_Carneiro !!
Welcome back
First your class need to have the IndexNullState set.
Note: This is not a mutable configuration.
With that on, you filter by null state.
here a code sample:
from weaviate.classes.config import Configure
from weaviate.classes.query import Filter
client.collections.delete("Collection")
collection = client.collections.create(
name="Collection",
vectorizer_config=Configure.Vectorizer.none(),
inverted_index_config=Configure.inverted_index(
index_null_state=True
)
)
# we add some data
collection.data.insert({"text": "Some text 1", "notext": "Hello"})
collection.data.insert({"text": "Some text 2"})
collection.data.insert({"text": "Some text 3"})
# now fetch only where notext is empty
result = collection.query.fetch_objects(
filters=Filter.by_property("notext").is_none(True)
)
for object in result.objects:
print(object.properties)
# now we delete
collection.data.delete_many(
where=Filter.by_property("notext").is_none(True)
)
# checking the deletion
from weaviate.classes.query import Filter
result = collection.query.fetch_objects()
for object in result.objects:
print(object.properties)
# output: {'text': 'Some text 1', 'notext': 'Hello'}
Let me know if this helps
Thanks!