Algolia search query by field not working

I have an index like the below:

[
  {
    "startDateTime": "2023-04-13 02:10:51",
    "eventType": "Book",
    "event": "ABC Launch",
    "authors": "Nick Leeson",
    "startTime": 1681351851,
    "eventID": 100
  },
  {
  "startDateTime": "2023-04-13 02:13:00",
  "eventType": "Book",
  "event": "XYZ Launch",
  "authors": "John Davidson",
  "startTime": 1681351980,
  "eventID": 101
  },
  {
  "startDateTime": "2023-04-13 04:26:20",
  "eventType": "Book",
  "event": "NEW Launch",
  "authors": "Nicole Swift",
  "startTime": 1681359980,
  "eventID": 102
  },
  {
  "startDateTime": "2023-04-13 07:13:00",
  "eventType": "Book",
  "event": "Kids Launch",
  "authors": "Timothy Smith",
  "startTime": 1681369980,
  "eventID": 103
  }
]

When I try to search by “authors” using java sdk, no results are returned. My code looks like:

Query query = new Query("authors");
query.setFilters("authors:'John Davidson'");

SearchResult<?> result = index.search(query);

The above result returns 0 hits. However the below query works:

Query query = new Query("authors");
query.setQuery("John Davidson");

SearchResult<?> result = index.search(query);

Can anyone please help me to understand what could be the issue? Also if I want to search multiple authors in a single query how can I do that?

Thanks

Hi @indranil.basu

In order to use an attribute as a filter, you must define it as a facet in your index configuration.

Can you confirm the “authors” attribute has been configured as a filter? You can find this in your index configuration via the Dashboard.

Screenshot 2023-04-13 at 11.31.08 AM

Thanks for your reply, it worked. One question? How do I type cast the response/result into an Object in typescript?