ElasticsearchQueryLucene.Core
1.2.0
See the version list below for details.
dotnet add package ElasticsearchQueryLucene.Core --version 1.2.0
NuGet\Install-Package ElasticsearchQueryLucene.Core -Version 1.2.0
<PackageReference Include="ElasticsearchQueryLucene.Core" Version="1.2.0" />
<PackageVersion Include="ElasticsearchQueryLucene.Core" Version="1.2.0" />
<PackageReference Include="ElasticsearchQueryLucene.Core" />
paket add ElasticsearchQueryLucene.Core --version 1.2.0
#r "nuget: ElasticsearchQueryLucene.Core, 1.2.0"
#:package ElasticsearchQueryLucene.Core@1.2.0
#addin nuget:?package=ElasticsearchQueryLucene.Core&version=1.2.0
#tool nuget:?package=ElasticsearchQueryLucene.Core&version=1.2.0
Elasticsearch Query DSL to Lucene Converter
A lightweight .NET library designed to bridge the gap between Elasticsearch's JSON-based Query DSL and the classic Lucene Query Syntax (String).
🚀 Key Features
- Comprehensive Query Support:
- Term Level:
term,terms,match,match_phrase,prefix,wildcard,fuzzy,regexp,exists,ids. - Ranges: Support for
gte,gt,lte,ltwith correct[]and{}bracket mapping. - Boolean Logic: Full support for
must(+),should(OR),must_not(-), andfilter(+) with recursive nesting.
- Term Level:
- Strict Input Validation:
- Max Size: 100KB per JSON string.
- Max Depth: 5 levels of query nesting to prevent stack overflow/DOS.
- Detailed Errors: Detailed error messages including line and column numbers for malformed JSON.
- Detailed Mapping Guide: Find the exact conversion rules for every supported query type.
- Architecture-First Design: Built using industry-standard patterns:
- Visitor Pattern: Separates traversal from syntax generation.
- Composite Pattern: Handles hierarchical query structures.
- Strategy Pattern: Routes JSON nodes to specific converters.
- Production Ready:
- Automatic Lucene character escaping (e.g.,
+,-,&&, etc.). - Comprehensive XUnit test suite.
- Verified against real
Lucene.Netexecution.
- Automatic Lucene character escaping (e.g.,
🏗 Architecture
The converter operates in two main stages:
- Parsing:
QueryParserreads the JSON and builds aQueryNodetree (Domain Model). - Conversion:
LuceneQueryVisitortraverses the tree and generates the final Lucene string.
💻 Usage
Basic Conversion
using ElasticsearchQueryLucene.Core.Converters;
string json = "{\"term\": {\"user.id\": \"kimchy\"}}";
var parser = new QueryParser();
var visitor = new LuceneQueryVisitor();
var queryNode = parser.Parse(json);
queryNode.Accept(visitor);
Console.WriteLine(visitor.GetResult()); // Output: user.id:kimchy
Real-Data Testing
The project includes a demo console application that indexes a sample book dataset and executes converted queries against Lucene.Net.
dotnet run --project src/ElasticsearchQueryLucene.Console
📂 Project Structure
| Path | Description |
|---|---|
src/ElasticsearchQueryLucene.Core |
Core logic, models, and visitor implementation. |
src/ElasticsearchQueryLucene.Console |
Live demo with real data and Lucene search engine. |
test/ElasticsearchQueryLucene.Tests |
Unit and integration tests. |
🛠 Prerequisites
- .NET 8.0 or later.
Lucene.Net(included in demo project).
| 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. |
-
net10.0
- No dependencies.
NuGet packages (1)
Showing the top 1 NuGet packages that depend on ElasticsearchQueryLucene.Core:
| Package | Downloads |
|---|---|
|
ElasticsearchQueryLucene.EntityFrameworkCore
A robust Entity Framework Core provider for Lucene.Net 4.8. Enabling full ORM capabilities (LINQ, Change Tracking, Paging) over Lucene indexes. |
GitHub repositories
This package is not used by any popular GitHub repositories.