Foundatio.Parsers.SqlQueries
8.0.0
Prefix Reserved
dotnet add package Foundatio.Parsers.SqlQueries --version 8.0.0
NuGet\Install-Package Foundatio.Parsers.SqlQueries -Version 8.0.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Foundatio.Parsers.SqlQueries" Version="8.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Foundatio.Parsers.SqlQueries" Version="8.0.0" />
<PackageReference Include="Foundatio.Parsers.SqlQueries" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Foundatio.Parsers.SqlQueries --version 8.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Foundatio.Parsers.SqlQueries, 8.0.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Foundatio.Parsers.SqlQueries@8.0.0
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Foundatio.Parsers.SqlQueries&version=8.0.0
#tool nuget:?package=Foundatio.Parsers.SqlQueries&version=8.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
An extensible Lucene-style query parser with support for Elasticsearch and SQL/Entity Framework Core. Build dynamic search APIs, custom dashboards, and powerful query interfaces.
Documentation
Installation
# Core Lucene parser
dotnet add package Foundatio.Parsers.LuceneQueries
# Elasticsearch integration
dotnet add package Foundatio.Parsers.ElasticQueries
# SQL/EF Core integration
dotnet add package Foundatio.Parsers.SqlQueries
Quick Start
Parse and Inspect Queries
using Foundatio.Parsers.LuceneQueries;
using Foundatio.Parsers.LuceneQueries.Visitors;
var parser = new LuceneQueryParser();
var result = parser.Parse("field:[1 TO 2]");
// Debug the AST structure
Console.WriteLine(DebugQueryVisitor.Run(result));
Output from DebugQueryVisitor:
Group:
Left - Term:
TermMax: 2
TermMin: 1
MinInclusive: True
MaxInclusive: True
Field:
Name: field
Regenerate the original query:
string query = GenerateQueryVisitor.Run(result);
// Output: "field:[1 TO 2]"
Build Elasticsearch Queries
using Foundatio.Parsers.ElasticQueries;
var parser = new ElasticQueryParser(c => c
.UseMappings(client, "my-index")
.UseFieldMap(new Dictionary<string, string> {
{ "user", "data.user.identity" }
}));
// Build NEST QueryContainer
var query = await parser.BuildQueryAsync("user:john AND status:active");
// Build aggregations
var aggs = await parser.BuildAggregationsAsync("terms:(status min:created max:created)");
// Build sort
var sort = await parser.BuildSortAsync("-created +name");
Build SQL/EF Core Queries
using Foundatio.Parsers.SqlQueries;
var parser = new SqlQueryParser(c => c
.SetDefaultFields(new[] { "Name", "Description" }));
var context = parser.GetContext(db.Products.EntityType);
string dynamicLinq = await parser.ToDynamicLinqAsync("status:active AND price:>100", context);
var results = await db.Products
.Where(parser.ParsingConfig, dynamicLinq)
.ToListAsync();
Features
Query Syntax
- Term queries:
field:value,field:"quoted phrase" - Range queries:
field:[1 TO 10],field:>100,field:>=2024-01-01 - Boolean operators:
AND,OR,NOT,+,- - Wildcards:
field:val*,field:va?ue - Existence:
_exists_:field,_missing_:field - Date math:
created:[now-7d TO now] - Geo queries:
location:75044~75mi
Aggregations
- Metrics:
min,max,avg,sum,stats,cardinality,percentiles - Buckets:
terms,date,histogram,geogrid,missing - Nested:
terms:(category min:price max:price)
Full Aggregation Syntax Reference
Field Aliases
Map user-friendly names to actual field paths:
var parser = new ElasticQueryParser(c => c
.UseFieldMap(new Dictionary<string, string> {
{ "user", "data.user.identity" },
{ "created", "metadata.createdAt" }
}));
Query Includes
Define reusable query macros:
var parser = new ElasticQueryParser(c => c
.UseIncludes(new Dictionary<string, string> {
{ "active", "status:active AND deleted:false" },
{ "recent", "created:[now-7d TO now]" }
}));
// Expands @include:active inline
var query = await parser.BuildQueryAsync("@include:active AND category:electronics");
Validation
Validate and restrict queries:
var parser = new ElasticQueryParser(c => c
.SetValidationOptions(new QueryValidationOptions {
AllowedFields = { "status", "name", "created" },
AllowLeadingWildcards = false,
AllowedMaxNodeDepth = 10
}));
var result = await parser.ValidateQueryAsync(userQuery);
if (!result.IsValid)
return BadRequest(result.Message);
Visitor Pattern
Extend with custom query transformations:
public class CustomVisitor : ChainableQueryVisitor
{
public override async Task VisitAsync(TermNode node, IQueryVisitorContext context)
{
// Custom transformation logic
await base.VisitAsync(node, context);
}
}
var parser = new ElasticQueryParser(c => c
.AddVisitor(new CustomVisitor(), priority: 100));
Use Cases
- Dynamic Search APIs - Let users build complex queries
- Custom Dashboards - User-defined aggregations and visualizations
- Saved Searches - Store and reuse query fragments
- Multi-tenant Filtering - Apply tenant filters transparently
- Query Translation - Parse once, output to multiple backends
Getting Started (Development)
- Clone the repository
- Open
Foundatio.Parsers.slnxin Visual Studio or VS Code - Build:
dotnet build - Test:
dotnet test
Thanks to all the people who have contributed
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net10.0
- Exceptionless.DateTimeExtensions (>= 6.0.1)
- Foundatio.Parsers.LuceneQueries (>= 8.0.0)
- Microsoft.EntityFrameworkCore.SqlServer (>= 10.0.0)
- System.Linq.Dynamic.Core (>= 1.7.2)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 8.0.0 | 110 | 5/12/2026 |
| 7.18.3 | 99 | 5/12/2026 |
| 7.18.2 | 128 | 5/9/2026 |
| 7.18.1 | 1,102 | 4/28/2026 |
| 7.18.0 | 93 | 4/25/2026 |
| 7.18.0-beta6 | 89 | 4/15/2026 |
| 7.18.0-beta5 | 87 | 4/15/2026 |
| 7.18.0-beta4 | 1,646 | 2/27/2026 |
| 7.18.0-beta3 | 1,992 | 2/14/2026 |
| 7.18.0-beta2 | 107 | 2/14/2026 |
| 7.18.0-beta1 | 111 | 1/12/2026 |
| 7.17.20 | 3,099 | 12/19/2025 |
| 7.17.19 | 917 | 11/25/2025 |
| 7.17.18 | 3,226 | 8/20/2025 |
| 7.17.17 | 4,189 | 5/15/2025 |
| 7.17.16 | 494 | 5/12/2025 |
| 7.17.15 | 157 | 5/9/2025 |
| 7.17.14 | 2,341 | 1/31/2025 |
| 7.17.13 | 601 | 1/13/2025 |
| 7.17.12 | 944 | 11/26/2024 |
Loading failed