Skip to content

Commit 2bf37f7

Browse files
committed
Added docs on aliases
1 parent 9c14f2a commit 2bf37f7

3 files changed

Lines changed: 100 additions & 2 deletions

File tree

README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,11 @@ by combining inserts or using aggressive caching.
496496

497497
For full details see the [docs on bulk operations](docs/bulk.md).
498498

499+
500+
501+
502+
503+
499504
## Show Query JSON
500505

501506
It can be useful to see the json output of requests in case you wish to tinker with the request in a REST client or your browser. It can be much easier to tweak a complicated query when you have the instant feedback of the HTTP interface.
@@ -513,6 +518,15 @@ Not all requests have a json body. For example _get-by-id_ is modelled purely by
513518

514519

515520

521+
522+
## Aliases
523+
524+
An [index alias](https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-aliases.html) is a logical name used to reference one or more indices. Most Elasticsearch APIs accept an index alias in place of an index name.
525+
526+
For elastic4s syntax for aliases [click here](docs/alias.md).
527+
528+
529+
516530
## Synchronous Operations
517531

518532
All operations are normally asynchronous. Sometimes though you might want to block - for example when doing snapshots or when creating the initial index. You can call `.await` on any operation to block until the result is ready. This is especially useful when testing.
@@ -525,6 +539,9 @@ val resp = client.execute {
525539

526540

527541

542+
543+
544+
528545
## Search Iterator
529546

530547
Sometimes you may wish to iterate over all the results in a search, without worrying too much about handling futures, and re-requesting
@@ -549,6 +566,10 @@ batch have been iterated on, the `SearchIterator` will then execute another quer
549566
So if you are looking for a pure non blocking solution, consider the reactive streams implementation. However, if you just want a
550567
quick and simple way to iterate over some data without bringing back all the results at once `SearchIterator` is perfect.
551568

569+
570+
571+
572+
552573
## Elastic Reactive Streams
553574

554575
Elastic4s has an implementation of the [reactive streams](http://www.reactive-streams.org) api for both publishing and subscribing that is built

docs/alias.md

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
## Alias
2+
3+
An [index alias](https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-aliases.html) is a logical name used to reference one or more indices. Most Elasticsearch APIs accept an index alias in place of an index name.
4+
5+
### Add and Remove
6+
7+
To add and remove aliases using elastic4s, we create instances of `AliasAction` and pass those to an `AliasRequest` which we can create manually or by the DSL method `aliases`.
8+
9+
For example, to add a single alias to the `beach` index.
10+
11+
```scala
12+
client.execute {
13+
aliases(
14+
addAlias("beaches_alias", "beach")
15+
)
16+
}
17+
```
18+
19+
We can perform multiple alias actions in a single request, including removal.
20+
21+
```scala
22+
client.execute {
23+
aliases(
24+
removeAlias("beaches_alias", "beach"),
25+
addAlias("mountains_alias", "mountains")
26+
)
27+
}
28+
```
29+
30+
### Filters
31+
32+
Aliases can also include [filters](https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-aliases.html#filtered).
33+
34+
```scala
35+
client.execute {
36+
aliases(
37+
addAlias("metal_beaches", "beaches").filter(prefixQuery("name", "g"))
38+
)
39+
}
40+
```
41+
42+
### Exists
43+
44+
To check if an alias exists, we can use:
45+
46+
```scala
47+
client.execute {
48+
aliasExists("mountains_alias")
49+
}
50+
```
51+
52+
### Get Aliases
53+
54+
We can retrieve aliases for a given index(es), or we can retrieve indexes for a given alias(es), or combinations therefore.
55+
56+
To lookup aliases used by one or more index:
57+
58+
```
59+
client.execute {
60+
getAliases(Seq("mountains", "beaches"), Nil)
61+
}
62+
```
63+
64+
And to lookup by alias:
65+
66+
```
67+
client.execute {
68+
getAliases(Nil, Seq("mountains_alias", "metal_beaches"))
69+
}
70+
```
71+

elastic4s-core/src/main/scala/com/sksamuel/elastic4s/requests/alias/AliasesApi.scala

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,25 @@ import scala.language.implicitConversions
66

77
trait AliasesApi {
88

9-
def aliases(first: AliasAction, rest: AliasAction*): IndicesAliasesRequest =
10-
aliases(first +: rest)
9+
def aliases(first: AliasAction, rest: AliasAction*): IndicesAliasesRequest = aliases(first +: rest)
1110
def aliases(actions: Iterable[AliasAction]) = IndicesAliasesRequest(actions.toSeq)
1211

1312
def addAlias(alias: String, index: String) = AddAliasActionRequest(alias, index)
13+
14+
@deprecated("use addAlias(alias, index)", "7.7.0")
1415
def addAlias(alias: String) = new AddAliasExpectsOn(alias)
16+
@deprecated("use addAlias(alias, index)", "7.7.0")
1517
class AddAliasExpectsOn(alias: String) {
18+
@deprecated("use addAlias(alias, index)", "7.7.0")
1619
def on(index: String) = AddAliasActionRequest(alias, index)
1720
}
1821

1922
def removeAlias(alias: String, index: String) = RemoveAliasAction(alias, index)
23+
@deprecated("use removeAlias(alias, index)", "7.7.0")
2024
def removeAlias(alias: String) = new RemoveAliasExpectsOn(alias)
25+
@deprecated("use removeAlias(alias, index)", "7.7.0")
2126
class RemoveAliasExpectsOn(alias: String) {
27+
@deprecated("use removeAlias(alias, index)", "7.7.0")
2228
def on(index: String) = RemoveAliasAction(alias, index)
2329
}
2430

0 commit comments

Comments
 (0)