OrchardCMS/OrchardCore · error · ArgumentException

Invalid value in boolean query

Error message

Invalid value in boolean query

What it means

In a boolean query, must/mustNot/should clause values must be JSON objects (query fragments). When the property is an array, each element must also be an object; any non-object element (string, number, etc.) throws this error.

Solutions

  1. Wrap each clause in a proper query object, e.g. {"term":{"field":"value"}}.
  2. Ensure every element of the must/mustNot/should arrays is a JSON object.
  3. Validate clause shape client-side before sending the query.

Example fix

// before
{"query":{"bool":{"should":["term"]}}}
// after
{"query":{"bool":{"should":[{"term":{"field":"value"}}]}}}
Defensive patterns

Strategy: validation

Validate before calling

if (clauses is JsonArray arr && arr.Any(c => c is not JsonObject))
    throw new ArgumentException("Every must/mustNot/should array element must be a query object.");

Type guard

static bool IsClauseArray(JsonNode? n) => n is not JsonArray a || a.All(i => i is JsonObject);

Try / catch

try { return builder.CreateQueryFragment(context, node); }
catch (ArgumentException ex) when (ex.Message == "Invalid value in boolean query") { /* show DSL error to user */ }

Prevention

When it happens

Trigger: Passing {"bool":{"should":["term"]}} or any array containing a non-object element.

Common situations: Hand-edited query JSON where a clause was left as a raw string, or programmatic builders that append raw values instead of query objects.

Understand the failure class

Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.

Related errors


AI-assisted analysis of OrchardCMS/OrchardCore@4306c0717f (2026-09-13). Data as JSON: /api/errors/1dfa35c83ab3a9af. Report an issue: GitHub.

Appendix: source

Thrown at src/OrchardCore/OrchardCore.Lucene.Core/QueryProviders/BooleanQueryProvider.cs:68

                    break;
                case "filter":
                    return CreateFilteredQuery(builder, context, boolQuery, property.Value);
                default: throw new ArgumentException($"Invalid property '{property.Key}' in boolean query");
            }

            if (!isProps)
            {
                switch (property.Value.GetValueKind())
                {
                    case JsonValueKind.Object:
                        boolQuery.Add(builder.CreateQueryFragment(context, property.Value.AsObject()), occur);
                        break;
                    case JsonValueKind.Array:
                        foreach (var item in property.Value.AsArray())
                        {
                            if (item.GetValueKind() != JsonValueKind.Object)
                            {
                                throw new ArgumentException($"Invalid value in boolean query");
                            }
                            boolQuery.Add(builder.CreateQueryFragment(context, item.AsObject()), occur);
                        }
                        break;
                    default: throw new ArgumentException($"Invalid value in boolean query");
                }
            }
        }

        return boolQuery;
    }

    private Query CreateFilteredQuery(ILuceneQueryService builder, LuceneQueryContext context, Query query, JsonNode filter)
    {
        Query filteredQuery;

        switch (filter.GetValueKind())
        {

View on GitHub (pinned to 4306c0717f)