Home > Blockchain >  How to check for inequality between fields in same document in Azure Cognitive search?
How to check for inequality between fields in same document in Azure Cognitive search?

Time:11-02

We have an index set up in Azure cognitive search that has two string fields (hash1 & hash2) containing separate hashes. We would like to query the index for documents where the two hashes within a document aren't equal.

I tried applying the filter: $filter=hash1 ne hash2, expecting the query to return all documents with mismatched hashes. Instead, I was greeted with the following error message:

"Invalid expression: Comparison must be between a field, range variable or function call and a literal value.\r\nParameter name: $filter"

From what I can gather there seems to be some kind of limitation preventing comparisons between fields. Would it be possible to perform this type of query in Azure cognitive search using a different technique?

CodePudding user response:

I would use content enrichment in this case. Even if comparing two hashes with a query was supported, it would be inefficient compared to pre-calculating the value using a content enrichment technique.

  1. Introduce a new boolean property called something like HasEqualHashes

  2. Populate that property with an appropriate boolean value

  3. Use a $filter to filter your content as you wish

    search=whatever&$filter=HasEqualHashes

Note that two different scenarios determine how you can enrich your content.

CONTENT SUBMITTED VIA SDK

When you use the SDK to submit content, you can enrich your items any way you want using regular code. Populating your HasEqualHashes property is a trivial one-liner in C#.

CONTENT SUBMITTED USING BUILT-IN INDEXERS

If you use one of the built-in indexers, you have to learn and understand the concept of skillsets.

Conceptual drawing of skillsets from microsoft.com

  • Related