go-query-dsl

module
v1.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 3, 2025 License: Apache-2.0

README

Go-Query-DSL

Go Reference

Go-Query-DSL is a Golang package designed to simplify the process of building queries for OpenSearch and Elasticsearch. This package supports various query types, enabling developers to interact with these search engines more easily and efficiently.

Features

  • Support for Multiple Query Types: Easily construct different types of queries such as match, term, range, bool, and more.
  • Flexible and Extensible: Build complex queries by combining basic queries using the bool query type.
  • Compatible with OpenSearch and Elasticsearch: Works with both search engines, leveraging their powerful querying capabilities.

Installation

To install Go-Query-DSL, use go get:

go get -u "go.companyinfo.dev/go-query-dsl"

Import the package in your Go code:

import "go.companyinfo.dev/go-query-dsl"

Usage

Basic Example

Here’s a simple example of how to use Go-Query-DSL to create a match query:

func main() {
	qb := query.New()

	qb.SetQuery(boolean.New().AddMust(match.New("first_name", match.NewParam("tom"))))
	q, err := qb.Build()
	if err != nil {
		return fmt.Errorf("failed on building a query: %w", err)
	}
	
	...
}

Supported Queries

Full Text Queries
  • Combined Fields: Searches across multiple fields as if they were a single field.
  • Intervals: Finds documents with terms that occur at specified intervals.
  • Match: Full-text search queries.
  • Match Bool Prefix: Combines match and bool queries with a prefix query.
  • Match Phrase: Searches for exact phrases in the text.
  • Match Phrase Prefix: Searches for phrases and prefixes with autocomplete capabilities.
  • Multi Match: Searches across multiple fields using different matching strategies.
  • Query String: Supports complex query strings with logical operators and field-specific searches.
Term Level Queries
  • Exists: Checks if a specific field exists in the document.
  • Fuzzy: Searches for terms that are similar to the specified value, with optional fuzziness.
  • IDs: Filters documents by specific document IDs.
  • Prefix: Searches for terms that start with a specified prefix.
  • Range: Queries for a range of values.
  • Regex: Uses regular expressions to search for matching patterns in text fields.
  • Term: Exact match queries.
  • Terms: Searches for documents that contain any of the specified terms.
  • Terms Set: Filters documents that match terms in a set with a minimum matching condition.
  • Wildcard: Uses wildcard patterns to search for matching terms.
Compound Queries
  • Bool: Combines multiple queries using must, should, must_not, and filter.
  • Boosting: Reduces the relevance score of documents matching the negative query.
  • Constant Score: Wraps another query and assigns a constant score to all matching documents.
  • Disjunction Max: Returns the highest score from any of the provided queries for each document.
Aggregation

Supports data aggregation and summarization, but specific implementations are not detailed here.

Sort

Orders search results based on specified field values or custom criteria.

Suggestion
  • Autocomplete: Provides suggestions as users type based on indexed terms.

Contribution

Contributions to Go-Query-DSL are welcome! If you find a bug, want to add a feature, or have suggestions for improvements, feel free to open issues or submit pull requests.

License

Copyright 2024 Company.info

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Directories

Path Synopsis
Package main provides a simple example for using the query builder.
Package main provides a simple example for using the query builder.
Package query provides a flexible and convenient way to build queries in Go.
Package query provides a flexible and convenient way to build queries in Go.
aggregation
Package aggregation provides structures and functions for building aggregation.
Package aggregation provides structures and functions for building aggregation.
compound/boolean
Package boolean provides structures and functions for building bool queries.
Package boolean provides structures and functions for building bool queries.
compound/boosting
Package boosting returns documents matching a positive query while reducing the relevance score of documents that also match a negative query.
Package boosting returns documents matching a positive query while reducing the relevance score of documents that also match a negative query.
compound/constantscore
Package constantscore wraps a filter query and returns every matching document with a relevance score equal to the boost parameter value.
Package constantscore wraps a filter query and returns every matching document with a relevance score equal to the boost parameter value.
compound/disjunctionmax
Package disjunctionmax A disjunction max (dis_max) query returns any document that matches one or more query clauses.
Package disjunctionmax A disjunction max (dis_max) query returns any document that matches one or more query clauses.
full_text/combinedfields
Package combinedfields provides structures and functions for building combined fields queries.
Package combinedfields provides structures and functions for building combined fields queries.
full_text/intervals
Package intervals provides structures and functions for building intervals queries.
Package intervals provides structures and functions for building intervals queries.
full_text/match
Package match provides structures and functions for building match queries.
Package match provides structures and functions for building match queries.
full_text/matchboolprefix
Package matchboolprefix provides structures and functions for building match boolean prefix queries.
Package matchboolprefix provides structures and functions for building match boolean prefix queries.
full_text/matchphrase
Package matchphrase provides structures and functions for building match phrase queries.
Package matchphrase provides structures and functions for building match phrase queries.
full_text/matchphraseprefix
Package matchphraseprefix provides structures and functions for building match phrase prefix queries.
Package matchphraseprefix provides structures and functions for building match phrase prefix queries.
full_text/multimatch
Package multimatch provides structures and functions for building multi-match queries.
Package multimatch provides structures and functions for building multi-match queries.
full_text/querystring
Package querystring provides structures and functions for building query string queries.
Package querystring provides structures and functions for building query string queries.
full_text/simplequerystring
Package simplequerystring provides structures and functions for building simple query string queries.
Package simplequerystring provides structures and functions for building simple query string queries.
sort
Package sort provides structures and functions for building sort parameters in queries.
Package sort provides structures and functions for building sort parameters in queries.
suggestion
Package suggestion accepts a list of suggestions and builds them into a finite-state transducer (FST), an optimized data structure that is essentially a graph.
Package suggestion accepts a list of suggestions and builds them into a finite-state transducer (FST), an optimized data structure that is essentially a graph.
term_level/exists
Package exists provides structures and functions for building exists queries.
Package exists provides structures and functions for building exists queries.
term_level/fuzzy
Package fuzzy provides structures and functions for building fuzzy queries.
Package fuzzy provides structures and functions for building fuzzy queries.
term_level/ids
Package ids provides structures and functions for building IDs queries.
Package ids provides structures and functions for building IDs queries.
term_level/prefix
Package prefix provides structures and functions for building prefix queries.
Package prefix provides structures and functions for building prefix queries.
term_level/range
Package ranging provides structures and functions for building range queries.
Package ranging provides structures and functions for building range queries.
term_level/regex
Package regex provides structures and functions for building regex queries.
Package regex provides structures and functions for building regex queries.
term_level/term
Package term provides structures and functions for building term queries.
Package term provides structures and functions for building term queries.
term_level/terms
Package terms provides structures and functions for building terms queries.
Package terms provides structures and functions for building terms queries.
term_level/termsset
Package termsset provides structures and functions for building terms set queries.
Package termsset provides structures and functions for building terms set queries.
term_level/wildcard
Package wildcard provides structures and functions for building wildcard queries.
Package wildcard provides structures and functions for building wildcard queries.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL