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.
- 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.
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"
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)
}
...
}
- 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.
- 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.
- 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.
Supports data aggregation and summarization, but specific implementations are not detailed here.
Orders search results based on specified field values or custom criteria.
- Autocomplete: Provides suggestions as users type based on indexed terms.
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.
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.