Skip to content

Commit 3a1cd62

Browse files
adding index module code examples (#2554)
* adding index module code examples * adding trailing comma
1 parent be7223c commit 3a1cd62

27 files changed

+426
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// index-modules/index-sorting.asciidoc:16
2+
3+
[source, python]
4+
----
5+
resp = client.indices.create(
6+
index="my-index-000001",
7+
body={
8+
"settings": {
9+
"index": {"sort.field": "date", "sort.order": "desc"}
10+
},
11+
"mappings": {"properties": {"date": {"type": "date"}}},
12+
},
13+
)
14+
print(resp)
15+
----
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// index-modules/allocation/delayed.asciidoc:40
2+
3+
[source, python]
4+
----
5+
resp = client.indices.put_settings(
6+
index="_all",
7+
body={
8+
"settings": {"index.unassigned.node_left.delayed_timeout": "5m"}
9+
},
10+
)
11+
print(resp)
12+
----
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// index-modules/similarity.asciidoc:22
2+
3+
[source, python]
4+
----
5+
resp = client.indices.create(
6+
index="index",
7+
body={
8+
"settings": {
9+
"index": {
10+
"similarity": {
11+
"my_similarity": {
12+
"type": "DFR",
13+
"basic_model": "g",
14+
"after_effect": "l",
15+
"normalization": "h2",
16+
"normalization.h2.c": "3.0",
17+
}
18+
}
19+
}
20+
}
21+
},
22+
)
23+
print(resp)
24+
----
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// index-modules/slowlog.asciidoc:31
2+
3+
[source, python]
4+
----
5+
resp = client.indices.put_settings(
6+
index="my-index-000001",
7+
body={
8+
"index.search.slowlog.threshold.query.warn": "10s",
9+
"index.search.slowlog.threshold.query.info": "5s",
10+
"index.search.slowlog.threshold.query.debug": "2s",
11+
"index.search.slowlog.threshold.query.trace": "500ms",
12+
"index.search.slowlog.threshold.fetch.warn": "1s",
13+
"index.search.slowlog.threshold.fetch.info": "800ms",
14+
"index.search.slowlog.threshold.fetch.debug": "500ms",
15+
"index.search.slowlog.threshold.fetch.trace": "200ms",
16+
},
17+
)
18+
print(resp)
19+
----
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// index-modules/allocation/delayed.asciidoc:95
2+
3+
[source, python]
4+
----
5+
resp = client.indices.put_settings(
6+
index="_all",
7+
body={"settings": {"index.unassigned.node_left.delayed_timeout": "0"}},
8+
)
9+
print(resp)
10+
----
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// index-modules/allocation/filtering.asciidoc:122
2+
3+
[source, python]
4+
----
5+
resp = client.indices.put_settings(
6+
index="test",
7+
body={"index.routing.allocation.include._ip": "192.168.2.*"},
8+
)
9+
print(resp)
10+
----
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// index-modules/slowlog.asciidoc:149
2+
3+
[source, python]
4+
----
5+
resp = client.indices.put_settings(
6+
index="my-index-000001",
7+
body={"index.indexing.slowlog.include.user": True},
8+
)
9+
print(resp)
10+
----
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// index-modules/slowlog.asciidoc:66
2+
3+
[source, python]
4+
----
5+
resp = client.indices.put_settings(
6+
index="my-index-000001",
7+
body={"index.search.slowlog.include.user": True},
8+
)
9+
print(resp)
10+
----
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// index-modules/similarity.asciidoc:540
2+
3+
[source, python]
4+
----
5+
resp = client.indices.close(
6+
index="index",
7+
)
8+
print(resp)
9+
10+
resp = client.indices.put_settings(
11+
index="index",
12+
body={"index": {"similarity": {"default": {"type": "boolean"}}}},
13+
)
14+
print(resp)
15+
16+
resp = client.indices.open(
17+
index="index",
18+
)
19+
print(resp)
20+
----
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// index-modules/similarity.asciidoc:45
2+
3+
[source, python]
4+
----
5+
resp = client.indices.put_mapping(
6+
index="index",
7+
body={
8+
"properties": {
9+
"title": {"type": "text", "similarity": "my_similarity"}
10+
}
11+
},
12+
)
13+
print(resp)
14+
----
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// index-modules/similarity.asciidoc:520
2+
3+
[source, python]
4+
----
5+
resp = client.indices.create(
6+
index="index",
7+
body={
8+
"settings": {
9+
"index": {"similarity": {"default": {"type": "boolean"}}}
10+
}
11+
},
12+
)
13+
print(resp)
14+
----
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// index-modules/similarity.asciidoc:357
2+
3+
[source, python]
4+
----
5+
resp = client.indices.create(
6+
index="index",
7+
body={
8+
"settings": {
9+
"number_of_shards": 1,
10+
"similarity": {
11+
"scripted_tfidf": {
12+
"type": "scripted",
13+
"weight_script": {
14+
"source": "double idf = Math.log((field.docCount+1.0)/(term.docFreq+1.0)) + 1.0; return query.boost * idf;"
15+
},
16+
"script": {
17+
"source": "double tf = Math.sqrt(doc.freq); double norm = 1/Math.sqrt(doc.length); return weight * tf * norm;"
18+
},
19+
}
20+
},
21+
},
22+
"mappings": {
23+
"properties": {
24+
"field": {"type": "text", "similarity": "scripted_tfidf"}
25+
}
26+
},
27+
},
28+
)
29+
print(resp)
30+
----
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// index-modules/store.asciidoc:30
2+
3+
[source, python]
4+
----
5+
resp = client.indices.create(
6+
index="my-index-000001",
7+
body={"settings": {"index.store.type": "hybridfs"}},
8+
)
9+
print(resp)
10+
----
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// index-modules/slowlog.asciidoc:133
2+
3+
[source, python]
4+
----
5+
resp = client.indices.put_settings(
6+
index="my-index-000001",
7+
body={
8+
"index.indexing.slowlog.threshold.index.warn": "10s",
9+
"index.indexing.slowlog.threshold.index.info": "5s",
10+
"index.indexing.slowlog.threshold.index.debug": "2s",
11+
"index.indexing.slowlog.threshold.index.trace": "500ms",
12+
"index.indexing.slowlog.source": "1000",
13+
},
14+
)
15+
print(resp)
16+
----
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// index-modules/allocation/prioritization.asciidoc:17
2+
3+
[source, python]
4+
----
5+
resp = client.indices.create(
6+
index="index_1",
7+
)
8+
print(resp)
9+
10+
resp = client.indices.create(
11+
index="index_2",
12+
)
13+
print(resp)
14+
15+
resp = client.indices.create(
16+
index="index_3",
17+
body={"settings": {"index.priority": 10}},
18+
)
19+
print(resp)
20+
21+
resp = client.indices.create(
22+
index="index_4",
23+
body={"settings": {"index.priority": 5}},
24+
)
25+
print(resp)
26+
----
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// index-modules/index-sorting.asciidoc:114
2+
3+
[source, python]
4+
----
5+
resp = client.indices.create(
6+
index="events",
7+
body={
8+
"settings": {
9+
"index": {"sort.field": "timestamp", "sort.order": "desc"}
10+
},
11+
"mappings": {"properties": {"timestamp": {"type": "date"}}},
12+
},
13+
)
14+
print(resp)
15+
----
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// index-modules/blocks.asciidoc:137
2+
3+
[source, python]
4+
----
5+
6+
----
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// index-modules/allocation/delayed.asciidoc:82
2+
3+
[source, python]
4+
----
5+
resp = client.cluster.health()
6+
print(resp)
7+
----
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// index-modules/allocation/prioritization.asciidoc:48
2+
3+
[source, python]
4+
----
5+
resp = client.indices.put_settings(
6+
index="index_4",
7+
body={"index.priority": 1},
8+
)
9+
print(resp)
10+
----
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// index-modules/allocation/filtering.asciidoc:74
2+
3+
[source, python]
4+
----
5+
resp = client.indices.put_settings(
6+
index="test",
7+
body={
8+
"index.routing.allocation.require.size": "big",
9+
"index.routing.allocation.require.rack": "rack1",
10+
},
11+
)
12+
print(resp)
13+
----
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// index-modules/index-sorting.asciidoc:41
2+
3+
[source, python]
4+
----
5+
resp = client.indices.create(
6+
index="my-index-000001",
7+
body={
8+
"settings": {
9+
"index": {
10+
"sort.field": ["username", "date"],
11+
"sort.order": ["asc", "desc"],
12+
}
13+
},
14+
"mappings": {
15+
"properties": {
16+
"username": {"type": "keyword", "doc_values": True},
17+
"date": {"type": "date"},
18+
}
19+
},
20+
},
21+
)
22+
print(resp)
23+
----
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// index-modules/allocation/filtering.asciidoc:54
2+
3+
[source, python]
4+
----
5+
resp = client.indices.put_settings(
6+
index="test",
7+
body={"index.routing.allocation.include.size": "big,medium"},
8+
)
9+
print(resp)
10+
----

0 commit comments

Comments
 (0)