Lucene Query Syntax
Parse standardized Lucene-style queries with support for terms, ranges, boolean operators, and wildcards.
Lucene-style query parsing with Elasticsearch and SQL support
Parse standardized Lucene-style queries with support for terms, ranges, boolean operators, and wildcards.
Enhanced query_string replacement that builds Elasticsearch Query, AggregationMap, and sort expressions.
Generate Dynamic LINQ queries from parsed expressions for Entity Framework Core applications.
Map field names with static dictionaries or dynamic resolvers for flexible query translation.
Define reusable query macros that expand inline, with recursive include detection.
Validate syntax, restrict fields, limit operations, and control nesting depth.
Extensible AST traversal with chainable visitors for custom query transformations.
Dynamic aggregation parsing for metrics, buckets, date histograms, and nested aggregations.
Support for geo proximity and bounding box queries with location resolution.
Automatic handling of Elasticsearch nested document queries, aggregations, sorting, negation, and exists/missing.
Parse a query and inspect its structure:
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));
// Regenerate the query string
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.name" }
}));
// Build an Elasticsearch Query
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");