ElasticsearchQueryLucene.Core 1.2.0

There is a newer version of this package available.
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
                    
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="ElasticsearchQueryLucene.Core" Version="1.2.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="ElasticsearchQueryLucene.Core" Version="1.2.0" />
                    
Directory.Packages.props
<PackageReference Include="ElasticsearchQueryLucene.Core" />
                    
Project file
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 ElasticsearchQueryLucene.Core --version 1.2.0
                    
#r "nuget: ElasticsearchQueryLucene.Core, 1.2.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 ElasticsearchQueryLucene.Core@1.2.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=ElasticsearchQueryLucene.Core&version=1.2.0
                    
Install as a Cake Addin
#tool nuget:?package=ElasticsearchQueryLucene.Core&version=1.2.0
                    
Install as a Cake Tool

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, lt with correct [] and {} bracket mapping.
    • Boolean Logic: Full support for must (+), should (OR), must_not (-), and filter (+) with recursive nesting.
  • 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.Net execution.

🏗 Architecture

The converter operates in two main stages:

  1. Parsing: QueryParser reads the JSON and builds a QueryNode tree (Domain Model).
  2. Conversion: LuceneQueryVisitor traverses 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 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

    • 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.

Version Downloads Last Updated
2.0.2 115 1/22/2026
2.0.1 109 1/22/2026
1.2.0 108 1/21/2026