Search code examples
azureazure-cosmosdbazure-cognitive-search

Azure Search Conditional Skill Compare Two Fields With Greater Than Equal To Operator


Question: Can Azure Cognitive Search's ConditionalSkill use a greater than or equal operator to compare two string fields or can it only do non-equality comparisons between numeric fields?

I'm looking to use the ConditionalSkill to compare two fields coming in from a Cosmos DB. Field1 and Field2. Both are string fields (or at least the comsos db data source seems to force it to be a string in the indexer). My goal is to create a new field in my search index called compareResults which is a Boolean. If field1 ('ABC') is greater than or equal to field2 ('DEF'), it should return true else return false.

The example provided on the docs pages seem to only show string equality between two fields and a greater than or equals to comparison for a numeric field and a literal value.

Error Message

My skillset is defined below but whenever I execute the indexer, I end up with an error detail of left Parameter name: left operand is not a number. However, when I switch to an equality operator == it works! This occurs whether field1 or field2 is a string or a number in cosmos db or a Edm.String or Edm.Int32 in the search index.

Skillset Definition

{
    "description": "Compare Fields",
    "name":"mycustomskill",
    "skills": [
        {
            "@odata.type": "#Microsoft.Skills.Util.ConditionalSkill",
            "context": "/document",
            "inputs": [
                {
                    "name": "condition",
                    "source": "= $(/document/field1) >= $(/document/field2)"
                },
                {
                    "name": "whenTrue",
                    "source": "= true"
                },
                {
                    "name": "whenFalse",
                    "source": "= false"
                }
            ],
            "outputs": [
                {
                    "name": "output",
                    "targetName": "compareResults"
                }
            ]
        }
    ],
    "cognitiveServices": {
        "@odata.type": "#Microsoft.Azure.Search.CognitiveServicesByKey",
        "description": "/subscriptions/x/resourceGroups/y/providers/Microsoft.CognitiveServices/accounts/z",
        "key": "abc123"
      }
}

Thank you for any guidance!


Solution

  • No, strings can only be compared for equality. The only work around for now is to use a Custom Web API to do the comparison externally. You can suggest adding string comparisons for the ConditionalSkill on UserVoice.