Total_count not working with filters on date values

Description

Hi community! I tried to get the total_count of a collection, with filters on some property with type date.

collection.aggregate.over_all(
    filters = Filter.by_property('published_date').greater_or_equal('2020-01-01T00:00:00Z')
).total_count

However, the following error message came up.

WeaviateQueryError: Query call with protocol GQL Aggregate failed with message Error in GraphQL response: [
  {
    "locations": [
      {
        "column": 12,
        "line": 1
      }
    ],
    "message": "invalid 'where' filter: data type filter cannot use \"valueText\" on type \"date\", use \"valueDate\" instead",
    "path": [
      "Aggregate",
      "Mycollection"
    ]
  }
], for the following query: {Aggregate{Mycollection(where: {path: ["published_date"] operator: GreaterThanEqual valueText: "2020-01-01T00:00:00Z"} ){meta{count}}}}.

Does someone encounter the same problem? Is there a way around?

Server Setup Information

  • Weaviate Server Version: 1.23.14
  • Deployment Method: docker
  • Multi Node? Number of Running Nodes: 1
  • Client Language and Version: Python 4.5.7
  • Multitenancy?: No

hi @longspearfish !!

Welcome to our community! :hugs:

This is a :bug: bug in the python client.
Edit: Not really…

this is because whatever you pass as the comparison argument, the client will infer the data type to pass it over to Weaviate.

So when you pass a date using string, it will use valueText instead of valueDate.

Hence the error code:

cannot use \"valueText\" on type \"date\", use \"valueDate\" instead"

Here is the client code for this

So you need to pass a python date object.

this will work:

from datetime import datetime
timestamp = "2020-01-01T00:00:00Z"
dt = datetime.strptime(timestamp, "%Y-%m-%dT%H:%M:%SZ")
collection.aggregate.over_all(
    filters = Filter.by_property('published_date').greater_or_equal(dt)
).total_count

Let me know if this helps!

Thanks!

1 Like

Yes it works! Thanks so much!

1 Like