Chris Brandsma
Chris Brandsma

Reputation: 11736

Azure Cognitive Search with boolean field

I'm using Azure Cognitive Search to basically host a Lucene search for me, and I'm using the C# interface for most things.

My document that I'm indexing has several boolean fields. Using the "Full" search syntax you can search individual fields using the syntax MyField:"value" or `MyField:("value1", "value2").

But what I cannot figure out is how to search on boolean fields. For example: MyBooleanField:"True" does not work, nor does MyBooleanField:"true".

My error is: Illegal arguments in query request: MyBooleanField is not a searchable field

The class is defined like this:

public class MyDocument 
{
    [SimpleField(IsFilterable = true, IsSortable = true, IsFacetable = true)]
    public bool MyBooleanField { get; set; }
}

Have any of you figured this out?

Upvotes: 0

Views: 1645

Answers (2)

Derek Legenzoff
Derek Legenzoff

Reputation: 136

Boolean fields aren't searchable so you can't reference them in your search expression.

Instead, you should use filtering to scope down the search results. In your case, the syntax would be:

$filter=MyBooleanField eq true 

This link also has some additional details and helpful examples: OData $filter syntax in Azure Cognitive Search

Upvotes: 3

Bruce Johnston
Bruce Johnston

Reputation: 8634

Boolean fields are not full-text searchable. You can use filters to match on them:

GET /indexes('myindex')/docs?$filter=MyBooleanField eq true&api-version=2020-06-30

Using the .NET SDK, you can set the Filter property on SearchOptions to an OData filter expression, in this case "MyBooleanField eq true".

Upvotes: 1

Related Questions