Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Opensearch #76

Merged
merged 3 commits into from
Jul 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 40 additions & 17 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -104,18 +104,23 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
java-version: [11]
es-major-version: [6, 7, 8]
include:
- es-major-version: 6
es-version: 6.8.23
es-config: elasticsearch.yml
- es-major-version: 7
es-version: 7.17.3
es-config: elasticsearch.yml
- es-major-version: 8
es-version: 8.1.2
es-config: elasticsearch-auth.yml
- es-distribution: elasticsearch
es-major-version: 6
es-image: elasticsearch:6.8.23
es-url: http://localhost:9200
- es-distribution: elasticsearch
es-major-version: 7
es-image: elasticsearch:7.17.3
es-url: http://localhost:9200
- es-distribution: elasticsearch
es-major-version: 8
es-image: elasticsearch:8.1.2
es-url: https://localhost:9200
- es-distribution: opensearch
es-major-version: 2
es-image: opensearchproject/opensearch:2.0.1
es-url: https://localhost:9200
steps:
- uses: actions/checkout@v2

Expand All @@ -125,35 +130,45 @@ jobs:
docker run -d \
--name elasticsearch \
-p 9200:9200 \
-v $(pwd)/${{ matrix.es-config }}:/usr/share/elasticsearch/config/elasticsearch.yml \
-e "discovery.type=single-node" \
-e "ES_JAVA_OPTS=-Xms128m -Xmx256m" \
--health-cmd="curl http://localhost:9200/_cluster/health" \
--health-cmd="curl ${{ matrix.es-url }} --insecure" \
--health-interval=5s \
--health-timeout=2s \
--health-retries=10 \
elasticsearch:${{ matrix.es-version }}
${{ matrix.es-image }}
echo -n "Waiting Elasticsearch "
until [ $(docker inspect -f '{{.State.Health.Status}}' elasticsearch) == "healthy" ]; do
sleep 1
echo -n .
done
echo "ELASTIC_URL=http://localhost:9200" >> $GITHUB_ENV

- name: Setup Elasticsearch password
if: ${{ matrix.es-major-version >= 8 }}
if: matrix.es-distribution == 'elasticsearch' && matrix.es-major-version >= 8
run: |
set -eux
set -eu
ELASTIC_PASSWORD=$( \
docker exec elasticsearch \
/usr/share/elasticsearch/bin/elasticsearch-reset-password --batch -u elastic | \
awk 'BEGIN { FS=": "; } /^New value:/ { print $2; }' \
)
echo "ELASTIC_URL=https://localhost:9200" >> $GITHUB_ENV
echo "ELASTIC_USER=elastic" >> $GITHUB_ENV
echo "ELASTIC_PASSWORD=$ELASTIC_PASSWORD" >> $GITHUB_ENV

- name: Opensearch settings
if: matrix.es-distribution == 'opensearch'
run: |
set -eu
echo "ELASTIC_URL=https://localhost:9200" >> $GITHUB_ENV
echo "ELASTIC_USER=admin" >> $GITHUB_ENV
echo "ELASTIC_PASSWORD=admin" >> $GITHUB_ENV

- name: Setup
uses: ./.github/setup
with:
java-version: ${{ matrix.java-version }}
java-version: 11

- name: Load caches
uses: ./.github/cache
Expand All @@ -164,18 +179,26 @@ jobs:
- name: Run integration tests
run: |
set -eux
# Allow self-signed certificates for JS engine: https://stackoverflow.com/a/66476468/473308
export NODE_TLS_REJECT_UNAUTHORIZED=0
export ELASTIC_URL='${{ env.ELASTIC_URL }}'
export ELASTIC_USER='${{ env.ELASTIC_USER }}'
export ELASTIC_PASSWORD='${{ env.ELASTIC_PASSWORD }}'
./gradlew :integ-tests:check $GRADLE_ARGS

- name: Run samples JVM
run: |
set -eux
export ELASTIC_URL='${{ env.ELASTIC_URL }}'
export ELASTIC_USER='${{ env.ELASTIC_USER }}'
export ELASTIC_PASSWORD='${{ env.ELASTIC_PASSWORD }}'
./gradlew run -p samples $GRADLE_ARGS

- name: Run samples native
run: |
set -eux
export ELASTIC_URL='${{ env.ELASTIC_URL }}'
export ELASTIC_USER='${{ env.ELASTIC_USER }}'
export ELASTIC_PASSWORD='${{ env.ELASTIC_PASSWORD }}'
./gradlew runDebugExecutableNative -p samples $GRADLE_ARGS

Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ Read [User Guide](https://anti-social.github.io/elasticmagic-kt/document/)
- Typed document source
- Parent child relations (ability to merge multiple documents into a single mapping)
- Focused on a search API
- Declarative search query modifications via `query filters`
- Supports several serialization libraries (`kotlinx.serialization` and `jackson` out of the box)
- Supports Elasticsearch `6.x`, `7.x` and `8.x` (autodetect Elasticsearch version)
- Supports Opensearch `1.x` and `2.x`

## Not a goal

Expand Down
20 changes: 19 additions & 1 deletion docs/docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,25 @@ First you need to describe a document (represents a mapping in terms of Elastics
Now create `ElasticsearchCluster` object. It is an entry point for executing search queries:

```kotlin
--8<-- "../samples/src/jvmMain/kotlin/samples/started/Cluster.kt"
--8<-- "../samples/src/commonMain/kotlin/samples/started/Cluster.kt"
```

Any `ElasticsearchCluster` needs an `ElasticsearchTransport`. We will use
the `ElasticsearchKtorTransport` that utilises [Ktor](https://ktor.io/docs/create-client.html)
http client.

Here are examples of creating transports for the cluster.

JVM:

```kotlin
--8<-- "../samples/src/jvmMain/kotlin/samples/started/ClusterJvm.kt"
```

Native:

```kotlin
--8<-- "../samples/src/nativeMain/kotlin/samples/started/ClusterNative.kt"
```

Create our index if it does not exist or update the mapping otherwise:
Expand Down
14 changes: 13 additions & 1 deletion docs/docs/query-filters.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,16 @@ Native version:
```shell
./gradlew :samples:linkBikeshopDebugExecutableNative
./samples/build/bin/native/bikeshopDebugExecutable/bikeshop.kexe
```
```

Both versions support following environment variables:

- `ELASTIC_URL` - URL to your Elasticsearch cluster. Default is `http://localhost:9200`.
If you want to use TLS change it to `https://localhost:9200`. Elasticsearch `8.x` and
Opensearch `2.x` turn on TLS by default.
- `ELASTIC_USER` - user for a basic authentication. Default is `elastic`.
Change it to `admin` if you use Opensearch.
- `ELASTIC_PASSWORD` - if this variable is set, basic authentication will be used.
Set it to a real password of your cluster or leave empty if your cluster doesn't require
authentication. Password for default configuration of Elasticsearch `8.x` can be found in logs.
Default password for Opensearch `2.x` is `admin`.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package dev.evo.elasticmagic.serde.serialization.compile

import dev.evo.elasticmagic.doc.Document
import dev.evo.elasticmagic.ElasticsearchVersion
import dev.evo.elasticmagic.SearchQuery
import dev.evo.elasticmagic.compile.ElasticsearchFeatures
import dev.evo.elasticmagic.usingIndex
import dev.evo.elasticmagic.compile.SearchQueryCompiler
import dev.evo.elasticmagic.serde.serialization.JsonSerializer
Expand All @@ -20,7 +20,7 @@ import kotlin.test.Test

class SearchQueryCompilerJsonTests {
private val compiler = SearchQueryCompiler(
ElasticsearchVersion(6, 0, 0),
ElasticsearchFeatures.ES_6_0
)

@Test
Expand Down
88 changes: 57 additions & 31 deletions elasticmagic/api/elasticmagic.api
Original file line number Diff line number Diff line change
Expand Up @@ -249,23 +249,6 @@ public final class dev/evo/elasticmagic/ElasticsearchIndex {
public final fun search (Ldev/evo/elasticmagic/BaseSearchQuery;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
}

public final class dev/evo/elasticmagic/ElasticsearchVersion : java/lang/Comparable {
public fun <init> (III)V
public fun compareTo (Ldev/evo/elasticmagic/ElasticsearchVersion;)I
public synthetic fun compareTo (Ljava/lang/Object;)I
public final fun component1 ()I
public final fun component2 ()I
public final fun component3 ()I
public final fun copy (III)Ldev/evo/elasticmagic/ElasticsearchVersion;
public static synthetic fun copy$default (Ldev/evo/elasticmagic/ElasticsearchVersion;IIIILjava/lang/Object;)Ldev/evo/elasticmagic/ElasticsearchVersion;
public fun equals (Ljava/lang/Object;)Z
public final fun getMajor ()I
public final fun getMinor ()I
public final fun getPatch ()I
public fun hashCode ()I
public fun toString ()Ljava/lang/String;
}

public final class dev/evo/elasticmagic/MultiSearchQueryResult {
public fun <init> (Ljava/lang/Long;Ljava/util/List;)V
public final fun component1 ()Ljava/lang/Long;
Expand Down Expand Up @@ -456,6 +439,48 @@ public final class dev/evo/elasticmagic/UpdateMappingResult {
public fun toString ()Ljava/lang/String;
}

public abstract class dev/evo/elasticmagic/Version : java/lang/Comparable {
public static final field Companion Ldev/evo/elasticmagic/Version$Companion;
}

public final class dev/evo/elasticmagic/Version$Companion {
public final fun compareVersions (IIIIII)I
}

public final class dev/evo/elasticmagic/Version$Elasticsearch : dev/evo/elasticmagic/Version {
public fun <init> (III)V
public fun compareTo (Ldev/evo/elasticmagic/Version$Elasticsearch;)I
public synthetic fun compareTo (Ljava/lang/Object;)I
public final fun component1 ()I
public final fun component2 ()I
public final fun component3 ()I
public final fun copy (III)Ldev/evo/elasticmagic/Version$Elasticsearch;
public static synthetic fun copy$default (Ldev/evo/elasticmagic/Version$Elasticsearch;IIIILjava/lang/Object;)Ldev/evo/elasticmagic/Version$Elasticsearch;
public fun equals (Ljava/lang/Object;)Z
public final fun getMajor ()I
public final fun getMinor ()I
public final fun getPatch ()I
public fun hashCode ()I
public fun toString ()Ljava/lang/String;
}

public final class dev/evo/elasticmagic/Version$Opensearch : dev/evo/elasticmagic/Version {
public fun <init> (III)V
public fun compareTo (Ldev/evo/elasticmagic/Version$Opensearch;)I
public synthetic fun compareTo (Ljava/lang/Object;)I
public final fun component1 ()I
public final fun component2 ()I
public final fun component3 ()I
public final fun copy (III)Ldev/evo/elasticmagic/Version$Opensearch;
public static synthetic fun copy$default (Ldev/evo/elasticmagic/Version$Opensearch;IIIILjava/lang/Object;)Ldev/evo/elasticmagic/Version$Opensearch;
public fun equals (Ljava/lang/Object;)Z
public final fun getMajor ()I
public final fun getMinor ()I
public final fun getPatch ()I
public fun hashCode ()I
public fun toString ()Ljava/lang/String;
}

public final class dev/evo/elasticmagic/aggs/AggRange {
public static final field Companion Ldev/evo/elasticmagic/aggs/AggRange$Companion;
public fun <init> ()V
Expand Down Expand Up @@ -1886,7 +1911,7 @@ public final class dev/evo/elasticmagic/bulk/UpdateSource$WithScript : dev/evo/e
}

public final class dev/evo/elasticmagic/compile/ActionCompiler : dev/evo/elasticmagic/compile/BaseCompiler {
public fun <init> (Ldev/evo/elasticmagic/ElasticsearchVersion;Ldev/evo/elasticmagic/compile/ActionMetaCompiler;Ldev/evo/elasticmagic/compile/ActionSourceCompiler;)V
public fun <init> (Ldev/evo/elasticmagic/compile/ElasticsearchFeatures;Ldev/evo/elasticmagic/compile/ActionMetaCompiler;Ldev/evo/elasticmagic/compile/ActionSourceCompiler;)V
public final fun compile (Ldev/evo/elasticmagic/serde/Serializer;Ldev/evo/elasticmagic/bulk/Action;)Ldev/evo/elasticmagic/compile/ActionCompiler$Compiled;
}

Expand All @@ -1905,28 +1930,27 @@ public final class dev/evo/elasticmagic/compile/ActionCompiler$Compiled {
}

public final class dev/evo/elasticmagic/compile/ActionMetaCompiler : dev/evo/elasticmagic/compile/BaseCompiler {
public fun <init> (Ldev/evo/elasticmagic/ElasticsearchVersion;)V
public fun <init> (Ldev/evo/elasticmagic/compile/ElasticsearchFeatures;)V
public final fun compile (Ldev/evo/elasticmagic/serde/Serializer;Ldev/evo/elasticmagic/bulk/Action;)Ldev/evo/elasticmagic/serde/Serializer$ObjectCtx;
}

public final class dev/evo/elasticmagic/compile/ActionSourceCompiler : dev/evo/elasticmagic/compile/BaseCompiler {
public fun <init> (Ldev/evo/elasticmagic/ElasticsearchVersion;Ldev/evo/elasticmagic/compile/SearchQueryCompiler;)V
public fun <init> (Ldev/evo/elasticmagic/compile/ElasticsearchFeatures;Ldev/evo/elasticmagic/compile/SearchQueryCompiler;)V
public final fun compile (Ldev/evo/elasticmagic/serde/Serializer;Ldev/evo/elasticmagic/bulk/Action;)Ldev/evo/elasticmagic/serde/Serializer$ObjectCtx;
}

public abstract class dev/evo/elasticmagic/compile/BaseCompiler {
public fun <init> (Ldev/evo/elasticmagic/ElasticsearchVersion;)V
public fun <init> (Ldev/evo/elasticmagic/compile/ElasticsearchFeatures;)V
public fun dispatch (Ldev/evo/elasticmagic/serde/Serializer$ArrayCtx;Ljava/lang/Object;)V
public fun dispatch (Ldev/evo/elasticmagic/serde/Serializer$ObjectCtx;Ljava/lang/String;Ljava/lang/Object;)V
public final fun getEsVersion ()Ldev/evo/elasticmagic/ElasticsearchVersion;
public final fun getFeatures ()Ldev/evo/elasticmagic/compile/ElasticsearchFeatures;
public final fun visit (Ldev/evo/elasticmagic/serde/Serializer$ArrayCtx;Ljava/util/List;)V
public final fun visit (Ldev/evo/elasticmagic/serde/Serializer$ArrayCtx;[Ljava/lang/Object;)V
public final fun visit (Ldev/evo/elasticmagic/serde/Serializer$ObjectCtx;Ljava/util/Map;)V
}

public final class dev/evo/elasticmagic/compile/BulkCompiler : dev/evo/elasticmagic/compile/BaseCompiler {
public fun <init> (Ldev/evo/elasticmagic/ElasticsearchVersion;Ldev/evo/elasticmagic/compile/ActionCompiler;)V
public fun <init> (Ldev/evo/elasticmagic/compile/ElasticsearchFeatures;Ldev/evo/elasticmagic/compile/ActionCompiler;)V
public final fun compile (Ldev/evo/elasticmagic/serde/Serializer;Ldev/evo/elasticmagic/compile/PreparedBulk;)Ldev/evo/elasticmagic/compile/BulkCompiler$Compiled;
public final fun processResult (Ldev/evo/elasticmagic/serde/Deserializer$ObjectCtx;)Ldev/evo/elasticmagic/BulkResult;
}
Expand All @@ -1940,20 +1964,21 @@ public final class dev/evo/elasticmagic/compile/BulkCompiler$Compiled {
}

public final class dev/evo/elasticmagic/compile/CompilerSet {
public fun <init> (Ldev/evo/elasticmagic/ElasticsearchVersion;)V
public fun <init> (Ldev/evo/elasticmagic/Version;)V
public final fun getActionCompiler ()Ldev/evo/elasticmagic/compile/ActionCompiler;
public final fun getActionMetaCompiler ()Ldev/evo/elasticmagic/compile/ActionMetaCompiler;
public final fun getActionSourceCompiler ()Ldev/evo/elasticmagic/compile/ActionSourceCompiler;
public final fun getBulk ()Ldev/evo/elasticmagic/compile/BulkCompiler;
public final fun getCreateIndex ()Ldev/evo/elasticmagic/compile/CreateIndexCompiler;
public final fun getFeatures ()Ldev/evo/elasticmagic/compile/ElasticsearchFeatures;
public final fun getMapping ()Ldev/evo/elasticmagic/compile/MappingCompiler;
public final fun getMultiSearchQuery ()Ldev/evo/elasticmagic/compile/MultiSearchQueryCompiler;
public final fun getSearchQuery ()Ldev/evo/elasticmagic/compile/SearchQueryCompiler;
public final fun getUpdateMapping ()Ldev/evo/elasticmagic/compile/UpdateMappingCompiler;
}

public final class dev/evo/elasticmagic/compile/CreateIndexCompiler : dev/evo/elasticmagic/compile/BaseCompiler {
public fun <init> (Ldev/evo/elasticmagic/ElasticsearchVersion;Ldev/evo/elasticmagic/compile/MappingCompiler;)V
public fun <init> (Ldev/evo/elasticmagic/compile/ElasticsearchFeatures;Ldev/evo/elasticmagic/compile/MappingCompiler;)V
public final fun compile (Ldev/evo/elasticmagic/serde/Serializer;Ldev/evo/elasticmagic/compile/PreparedCreateIndex;)Ldev/evo/elasticmagic/transport/JsonRequest;
public final fun getMappingCompiler ()Ldev/evo/elasticmagic/compile/MappingCompiler;
public final fun processResult (Ldev/evo/elasticmagic/serde/Deserializer$ObjectCtx;)Ldev/evo/elasticmagic/CreateIndexResult;
Expand All @@ -1970,12 +1995,13 @@ public final class dev/evo/elasticmagic/compile/ElasticsearchFeatures : java/lan
}

public final class dev/evo/elasticmagic/compile/ElasticsearchFeatures$Companion {
public final fun getVERSION_FEATURES ()Ljava/util/List;
public final fun invoke (Ldev/evo/elasticmagic/ElasticsearchVersion;)Ldev/evo/elasticmagic/compile/ElasticsearchFeatures;
public final fun getES_VERSION_FEATURES ()Ljava/util/List;
public final fun getOS_VERSION_FEATURES ()Ljava/util/List;
public final fun invoke (Ldev/evo/elasticmagic/Version;)Ldev/evo/elasticmagic/compile/ElasticsearchFeatures;
}

public class dev/evo/elasticmagic/compile/MappingCompiler : dev/evo/elasticmagic/compile/BaseCompiler {
public fun <init> (Ldev/evo/elasticmagic/ElasticsearchVersion;Ldev/evo/elasticmagic/compile/SearchQueryCompiler;)V
public fun <init> (Ldev/evo/elasticmagic/compile/ElasticsearchFeatures;Ldev/evo/elasticmagic/compile/SearchQueryCompiler;)V
public final fun compile (Ldev/evo/elasticmagic/serde/Serializer;Ldev/evo/elasticmagic/doc/Document;)Ldev/evo/elasticmagic/compile/MappingCompiler$Compiled;
public fun dispatch (Ldev/evo/elasticmagic/serde/Serializer$ArrayCtx;Ljava/lang/Object;)V
public fun dispatch (Ldev/evo/elasticmagic/serde/Serializer$ObjectCtx;Ljava/lang/String;Ljava/lang/Object;)V
Expand All @@ -1994,7 +2020,7 @@ public final class dev/evo/elasticmagic/compile/MappingCompiler$Compiled {
}

public final class dev/evo/elasticmagic/compile/MultiSearchQueryCompiler : dev/evo/elasticmagic/compile/BaseCompiler {
public fun <init> (Ldev/evo/elasticmagic/ElasticsearchVersion;Ldev/evo/elasticmagic/compile/SearchQueryCompiler;)V
public fun <init> (Ldev/evo/elasticmagic/compile/ElasticsearchFeatures;Ldev/evo/elasticmagic/compile/SearchQueryCompiler;)V
public final fun compile (Ldev/evo/elasticmagic/serde/Serializer;Ljava/util/List;)Ldev/evo/elasticmagic/transport/BulkRequest;
}

Expand Down Expand Up @@ -2032,7 +2058,7 @@ public final class dev/evo/elasticmagic/compile/PreparedUpdateMapping {
}

public class dev/evo/elasticmagic/compile/SearchQueryCompiler : dev/evo/elasticmagic/compile/BaseCompiler {
public fun <init> (Ldev/evo/elasticmagic/ElasticsearchVersion;)V
public fun <init> (Ldev/evo/elasticmagic/compile/ElasticsearchFeatures;)V
public final fun compile (Ldev/evo/elasticmagic/serde/Serializer;Ldev/evo/elasticmagic/PreparedSearchQuery;Ljava/lang/String;)Ldev/evo/elasticmagic/transport/JsonRequest;
public final fun compile (Ldev/evo/elasticmagic/serde/Serializer;Ldev/evo/elasticmagic/SearchQueryWithIndex;)Ldev/evo/elasticmagic/transport/JsonRequest;
public fun dispatch (Ldev/evo/elasticmagic/serde/Serializer$ArrayCtx;Ljava/lang/Object;)V
Expand All @@ -2048,7 +2074,7 @@ public abstract interface class dev/evo/elasticmagic/compile/SearchQueryCompiler
}

public final class dev/evo/elasticmagic/compile/UpdateMappingCompiler : dev/evo/elasticmagic/compile/BaseCompiler {
public fun <init> (Ldev/evo/elasticmagic/ElasticsearchVersion;Ldev/evo/elasticmagic/compile/MappingCompiler;)V
public fun <init> (Ldev/evo/elasticmagic/compile/ElasticsearchFeatures;Ldev/evo/elasticmagic/compile/MappingCompiler;)V
public final fun compile (Ldev/evo/elasticmagic/serde/Serializer;Ldev/evo/elasticmagic/compile/PreparedUpdateMapping;)Ldev/evo/elasticmagic/transport/JsonRequest;
public final fun processResult (Ldev/evo/elasticmagic/serde/Deserializer$ObjectCtx;)Ldev/evo/elasticmagic/UpdateMappingResult;
}
Expand Down
Loading