https://github.com/just-sultanov/elastiq
An experimental library for building queries to the Elastic (OpenSearch) Search API
https://github.com/just-sultanov/elastiq
clojure elasticsearch opensearch query-builder
Last synced: 5 months ago
JSON representation
An experimental library for building queries to the Elastic (OpenSearch) Search API
- Host: GitHub
- URL: https://github.com/just-sultanov/elastiq
- Owner: just-sultanov
- License: mit
- Created: 2024-03-16T18:20:21.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-03-19T20:40:54.000Z (over 2 years ago)
- Last Synced: 2025-06-10T22:39:24.166Z (about 1 year ago)
- Topics: clojure, elasticsearch, opensearch, query-builder
- Language: Clojure
- Homepage:
- Size: 18.6 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: license
Awesome Lists containing this project
README
# elastiq
An experimental library for building queries to the Elastic (OpenSearch) Search
API.
## How it works
- Provide mappings of your `index`
- Automatically create a `malli` schema using mappings of your `index`
- Validate a user request
- Transform a user request into a request to the Elastic (OpenSearch) Search API
using the `malli` scheme created above
**User request**
```jsonc
{
"from": 0,
"size": 100,
"query": {
"article": { "content": "clojure" }, // `content` contains "clojure"
"tags": ["clojure", "clojurescript"], // `tag` is equal to "clojure" or "clojurescript"
"author": "*", // `author` is not `empty` or `null`
"public": true, // only `public` articles
"published_at": { "from": "2024-01-01", "to": "now" } // articles for the specified period
}
}
```
**Generated query to the Elastic (OpenSearch) Search API**
```clojure
{:from 0,
:size 100,
:query {:bool
{:must [{:nested {:path :article
:query {:bool {:must [{:match {:article.content "clojure"}}]}}}}
{:bool {:minimum_should_match 1
:should [{:match {:tags {:query "clojure"}}}
{:match {:tags {:query "clojurescript"}}}]}}
{:exists {:field :author}}
{:term {:public true}}
{:range {:published_at {:gte "2024-01-01", :lte "now"}}}]}}}
```
**Mappings**
```json
{
"posts": {
"mappings": {
"doc": {
"_meta": {
"applicationVersion": "14.15"
},
"properties": {
"article": {
"type": "nested",
"properties": {
"title": {
"type": "keyword"
},
"content": {
"type": "text",
"analyzer": "some_text_analyzer"
}
}
},
"tags": {
"type": "keyword"
},
"author": {
"type": "keyword"
},
"public": {
"type": "boolean"
},
"published_at": {
"type": "date"
}
}
}
}
}
}
```
## License
[Copyright © 2024 Ilshat Sultanov](./license)