You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This creates the index and uses the mappings and settings DSL. With this DSL, you can map fields,
189
+
This creates the index and uses the **mappings and settings DSL**. With this DSL, you can map fields,
176
190
configure analyzers, etc. This is optional of course; you can just call it without the block
177
191
and use the defaults and rely on dynamic mapping.
178
192
You can read more about that [here](https://jillesvangurp.github.io/kt-search/manual/IndexManagement.html)
179
193
180
194
### Adding documents
181
195
182
-
To fill the index with some content, we need to use bulk operations.
196
+
To fill the index with some documents, we need to use bulk indexing operations.
197
+
198
+
In kt-search this is made very easy with a **Bulk Indexing DSL** that completely abstracts away the book keeping
199
+
that you need to do for this in other clients.
183
200
184
-
In kt-search this is made very easy with a DSL that abstracts away the book keeping
185
-
that you need to do for this. The bulk block below creates a `BulkSession`, which does this for you and flushes
201
+
The bulk block below creates a `BulkSession`, which does this for you and flushes
186
202
operations to Elasticsearch. You can configure and tailor how this works via parameters
187
203
that have sensible defaults. For example the number of operations that is flushed is something
188
-
that you'd want to probably configure.
204
+
that you'd want to probably configure and error handling is something you can customize as well.
189
205
190
206
The optional `refresh` parameter uses WaitFor as the default. This means that after the block exits, the documents
191
207
will have been indexed and are available for searching.
@@ -194,7 +210,7 @@ will have been indexed and are available for searching.
194
210
client.bulk(
195
211
refresh =Refresh.WaitFor,
196
212
// send operations every 2 ops
197
-
// default would be 100
213
+
// default and more sensible would be 100
198
214
bulkSize =2,
199
215
) {
200
216
index(
@@ -222,7 +238,7 @@ client.bulk(
222
238
```
223
239
224
240
You can read more about
225
-
[bulk operations](https://jillesvangurp.github.io/kt-search/manual/BulkIndexing.html) in the manual.
241
+
[bulk operations](https://jillesvangurp.github.io/kt-search/manual/BulkIndexing.html)and how to customize it in the manual.
226
242
227
243
### Search
228
244
@@ -231,10 +247,11 @@ Now that we have some documents in an index, we can do some queries:
231
247
```kotlin
232
248
// search for some fruit
233
249
val results = client.search(indexName) {
250
+
// `this` is a SearchDSL instance in the block
234
251
query = bool {
235
252
must(
236
-
// note how we can use property references here
237
-
term(TestDocument::tags, "fruit"),
253
+
term("tags", "fruit"),
254
+
// note how we can also use property references here
238
255
matchPhrasePrefix(TestDocument::name, "app")
239
256
)
240
257
}
@@ -263,7 +280,10 @@ doc apple
263
280
{"name":"apple","tags":["fruit"]}
264
281
```
265
282
266
-
You can also construct complex aggregations with the query DSL:
283
+
You can also construct complex aggregations with the query DSL.
284
+
Aggregation queries are one of the more complex topics in Elasticsearch
285
+
and we worked hard to make constructing these programmatically from
286
+
Kotlin as easy as possible.
267
287
268
288
```kotlin
269
289
val resp = client.search(indexName) {
@@ -275,7 +295,8 @@ val resp = client.search(indexName) {
275
295
minDocCount =1
276
296
})
277
297
}
278
-
// picking the results apart is just as easy.
298
+
// Despite aggregations JSON being very complicated,
299
+
// kt-search makes picking the results apart easy.
279
300
resp.aggregations
280
301
.termsResult("by-tag")
281
302
.parsedBuckets.forEach { bucket ->
@@ -295,16 +316,18 @@ These examples show off a few nice features of this library:
295
316
296
317
- Kotlin DSLs are nice, type safe, and easier to read and write than pure Json. And of course
297
318
you get auto completion too. The client includes more DSLs for searching, creating indices and mappings, datastreams,
298
-
index life cycle management, bulk operations, aggregations, and more.
319
+
index life cycle management, bulk operations, aggregations, and more. All this builds on
320
+
[JsonDSL](https://github.com/jillesvangurp/json-dsl), which is a library we created for easily creating
321
+
Kotlin DSLs for existing JSON dialects.
299
322
- Where in JSON, you use a lot of String literals, kt-search actually allows you to use
300
-
property references or enum values as well. So, refactoring your data model doesn't
323
+
property references or enum values as well. If you use those, refactoring your data model doesn't
301
324
break your mappings and queries.
302
325
- Kt-search makes complicated features like bulk operations, aggregations, etc. really easy
303
-
to use and accessible. And there is also the IndexRepository, which makes it extremely easy
326
+
to use and accessible. And there is also the `IndexRepository`, which makes it extremely easy
304
327
to work with and query documents in a given index or data stream.
305
-
- While a DSL is nice to have, sometimes it just doesn't have the feature you
306
-
need or maybe you want to work with raw json string literal. Kt-search allows you to do both
307
-
and mix schema less with type safe kotlin. You can easily add custom
328
+
- While a Kotlin DSL is nice to have, sometimes it just doesn't have the feature you
329
+
need or maybe you want to work with raw json and use Kotlin's multiline string literals.
330
+
Kt-search allows you to do both and mix schema less with type safe kotlin. You can easily add custom
308
331
properties to the DSL via a simple `put`. All `JsonDsl` are actually mutable maps.
309
332
- Kt-search is designed to be [extensible](https://jillesvangurp.github.io/kt-search/manual/ExtendingTheDSL.html).
310
333
It's easy to use the built in features. And you can easily add your own features. This also
@@ -382,8 +405,8 @@ There are several libraries that build on kt-search:
382
405
383
406
Additionally, I also maintain a few other search related projects that you might find interesting.
384
407
385
-
-[Rankquest Studio](https://rankquest.jillesvangurp.com) - A user friendly tool that requires no installation process that helps you build and run test cases to measure search relevance for your search products. Rankquest Studio of course uses kt-search but it is also able to talk directly to your API and is designed to work with any kind of search api or product that is able to return lists of results.
386
-
-[querylight](https://github.com/jillesvangurp/querylight) - Sometimes Elasticsearch is just overkill. Query light is a tiny in memory search engine that you can embed in your kotlin browser, server, or mobile applications. We use it at FORMATION to support e.g. in app icon search. Querylight comes with its own analyzers and query language.
408
+
-[Rankquest Studio](https://rankquest.jillesvangurp.com) - A user friendly tool that requires no installation process that helps you build and run test cases to measure search relevance for your search products. Rankquest Studio of course uses kt-search but it is also able to talk directly to your search API and is designed to work with any kind of search api or product that is able to return lists of results.
409
+
-[querylight](https://github.com/jillesvangurp/querylight) - Sometimes Elasticsearch/Opensearch is just overkill. Query light is a tiny but capable in memory search engine that you can embed in your kotlin browser, server, or mobile applications. We use it at FORMATION to support e.g. in app icon search. Querylight comes with its own analyzers and query language.
0 commit comments