How can I compare two fields in one document?

I want to perform a search that returns records only if two fields match. Lets say I have the following data:

[{
  id: 1,
  fieldA: 123,
  fieldB: 123
}, {
  id: 2,
  fieldA: 123,
  fieldB: 456
}]

Only the first record with id 1 should be returned. Is there anyway to do this in Algolia?

I was trying the Facet filters, but it seams those only pick up literal values for comparison. I was also looking into grouping and distinct but that seems to only group by one field. It would be nice if I could dynamically choose which fields to compare on the fly. For example, I may have 6 fields, and want to do this search on field a and b in one scenario, and b and c in another.