Skip to content

Commit

Permalink
adding index module code examples (#2554)
Browse files Browse the repository at this point in the history
* adding index module code examples

* adding trailing comma
  • Loading branch information
anniegale9538 committed May 17, 2024
1 parent be7223c commit 3a1cd62
Show file tree
Hide file tree
Showing 27 changed files with 426 additions and 0 deletions.
15 changes: 15 additions & 0 deletions docs/examples/156bc64c94f9f3334fbce25165d2286a.asciidoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// index-modules/index-sorting.asciidoc:16

[source, python]
----
resp = client.indices.create(
index="my-index-000001",
body={
"settings": {
"index": {"sort.field": "date", "sort.order": "desc"}
},
"mappings": {"properties": {"date": {"type": "date"}}},
},
)
print(resp)
----
12 changes: 12 additions & 0 deletions docs/examples/17e6f3fac556f08a78f7a876e71acb89.asciidoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// index-modules/allocation/delayed.asciidoc:40

[source, python]
----
resp = client.indices.put_settings(
index="_all",
body={
"settings": {"index.unassigned.node_left.delayed_timeout": "5m"}
},
)
print(resp)
----
24 changes: 24 additions & 0 deletions docs/examples/2342a56279106ea643026df657bf7f88.asciidoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// index-modules/similarity.asciidoc:22

[source, python]
----
resp = client.indices.create(
index="index",
body={
"settings": {
"index": {
"similarity": {
"my_similarity": {
"type": "DFR",
"basic_model": "g",
"after_effect": "l",
"normalization": "h2",
"normalization.h2.c": "3.0",
}
}
}
}
},
)
print(resp)
----
19 changes: 19 additions & 0 deletions docs/examples/23af230e824f48b9cd56a4cf973d788c.asciidoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// index-modules/slowlog.asciidoc:31

[source, python]
----
resp = client.indices.put_settings(
index="my-index-000001",
body={
"index.search.slowlog.threshold.query.warn": "10s",
"index.search.slowlog.threshold.query.info": "5s",
"index.search.slowlog.threshold.query.debug": "2s",
"index.search.slowlog.threshold.query.trace": "500ms",
"index.search.slowlog.threshold.fetch.warn": "1s",
"index.search.slowlog.threshold.fetch.info": "800ms",
"index.search.slowlog.threshold.fetch.debug": "500ms",
"index.search.slowlog.threshold.fetch.trace": "200ms",
},
)
print(resp)
----
10 changes: 10 additions & 0 deletions docs/examples/25d40d3049e57e2bb70c2c5b88bd7b87.asciidoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// index-modules/allocation/delayed.asciidoc:95

[source, python]
----
resp = client.indices.put_settings(
index="_all",
body={"settings": {"index.unassigned.node_left.delayed_timeout": "0"}},
)
print(resp)
----
10 changes: 10 additions & 0 deletions docs/examples/28ac880057135e46b3b00c7f3976538c.asciidoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// index-modules/allocation/filtering.asciidoc:122

[source, python]
----
resp = client.indices.put_settings(
index="test",
body={"index.routing.allocation.include._ip": "192.168.2.*"},
)
print(resp)
----
10 changes: 10 additions & 0 deletions docs/examples/2f07b81fd47ec3b074242a760f0c4e9e.asciidoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// index-modules/slowlog.asciidoc:149

[source, python]
----
resp = client.indices.put_settings(
index="my-index-000001",
body={"index.indexing.slowlog.include.user": True},
)
print(resp)
----
10 changes: 10 additions & 0 deletions docs/examples/34cdeefb09bbbe5206957a8bc1bd513d.asciidoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// index-modules/slowlog.asciidoc:66

[source, python]
----
resp = client.indices.put_settings(
index="my-index-000001",
body={"index.search.slowlog.include.user": True},
)
print(resp)
----
20 changes: 20 additions & 0 deletions docs/examples/48de51de87a8ad9fd8b8db1ca25b85c1.asciidoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// index-modules/similarity.asciidoc:540

[source, python]
----
resp = client.indices.close(
index="index",
)
print(resp)
resp = client.indices.put_settings(
index="index",
body={"index": {"similarity": {"default": {"type": "boolean"}}}},
)
print(resp)
resp = client.indices.open(
index="index",
)
print(resp)
----
14 changes: 14 additions & 0 deletions docs/examples/528e5f1c345c3769248cc6889e8cf552.asciidoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// index-modules/similarity.asciidoc:45

[source, python]
----
resp = client.indices.put_mapping(
index="index",
body={
"properties": {
"title": {"type": "text", "similarity": "my_similarity"}
}
},
)
print(resp)
----
14 changes: 14 additions & 0 deletions docs/examples/553d79817bb1333970e99507c37a159a.asciidoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// index-modules/similarity.asciidoc:520

[source, python]
----
resp = client.indices.create(
index="index",
body={
"settings": {
"index": {"similarity": {"default": {"type": "boolean"}}}
}
},
)
print(resp)
----
30 changes: 30 additions & 0 deletions docs/examples/5f8fb5513d4f725434db2f517ad4298f.asciidoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// index-modules/similarity.asciidoc:357

[source, python]
----
resp = client.indices.create(
index="index",
body={
"settings": {
"number_of_shards": 1,
"similarity": {
"scripted_tfidf": {
"type": "scripted",
"weight_script": {
"source": "double idf = Math.log((field.docCount+1.0)/(term.docFreq+1.0)) + 1.0; return query.boost * idf;"
},
"script": {
"source": "double tf = Math.sqrt(doc.freq); double norm = 1/Math.sqrt(doc.length); return weight * tf * norm;"
},
}
},
},
"mappings": {
"properties": {
"field": {"type": "text", "similarity": "scripted_tfidf"}
}
},
},
)
print(resp)
----
10 changes: 10 additions & 0 deletions docs/examples/7b3e913368e96eaa6e22e0d03c81310e.asciidoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// index-modules/store.asciidoc:30

[source, python]
----
resp = client.indices.create(
index="my-index-000001",
body={"settings": {"index.store.type": "hybridfs"}},
)
print(resp)
----
16 changes: 16 additions & 0 deletions docs/examples/844928da2ff9a1394af5347a5e2e4f78.asciidoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// index-modules/slowlog.asciidoc:133

[source, python]
----
resp = client.indices.put_settings(
index="my-index-000001",
body={
"index.indexing.slowlog.threshold.index.warn": "10s",
"index.indexing.slowlog.threshold.index.info": "5s",
"index.indexing.slowlog.threshold.index.debug": "2s",
"index.indexing.slowlog.threshold.index.trace": "500ms",
"index.indexing.slowlog.source": "1000",
},
)
print(resp)
----
26 changes: 26 additions & 0 deletions docs/examples/8703f3b1b3895543abc36e2a7a0013d3.asciidoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// index-modules/allocation/prioritization.asciidoc:17

[source, python]
----
resp = client.indices.create(
index="index_1",
)
print(resp)
resp = client.indices.create(
index="index_2",
)
print(resp)
resp = client.indices.create(
index="index_3",
body={"settings": {"index.priority": 10}},
)
print(resp)
resp = client.indices.create(
index="index_4",
body={"settings": {"index.priority": 5}},
)
print(resp)
----
15 changes: 15 additions & 0 deletions docs/examples/8d7193902a353872740a3324c60c5001.asciidoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// index-modules/index-sorting.asciidoc:114

[source, python]
----
resp = client.indices.create(
index="events",
body={
"settings": {
"index": {"sort.field": "timestamp", "sort.order": "desc"}
},
"mappings": {"properties": {"timestamp": {"type": "date"}}},
},
)
print(resp)
----
6 changes: 6 additions & 0 deletions docs/examples/9de4ea9d5f3d427a71ee07d998cb5611.asciidoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// index-modules/blocks.asciidoc:137

[source, python]
----
----
7 changes: 7 additions & 0 deletions docs/examples/a38f29375eabd0103f8d7c00b17bb0ab.asciidoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// index-modules/allocation/delayed.asciidoc:82

[source, python]
----
resp = client.cluster.health()
print(resp)
----
10 changes: 10 additions & 0 deletions docs/examples/a425fcab60f603504becee7d001f0a4b.asciidoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// index-modules/allocation/prioritization.asciidoc:48

[source, python]
----
resp = client.indices.put_settings(
index="index_4",
body={"index.priority": 1},
)
print(resp)
----
13 changes: 13 additions & 0 deletions docs/examples/beba2a9795c8a13653e1edf64eec4357.asciidoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// index-modules/allocation/filtering.asciidoc:74

[source, python]
----
resp = client.indices.put_settings(
index="test",
body={
"index.routing.allocation.require.size": "big",
"index.routing.allocation.require.rack": "rack1",
},
)
print(resp)
----
23 changes: 23 additions & 0 deletions docs/examples/d4fb482a51d67a1af48e429af6019a46.asciidoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// index-modules/index-sorting.asciidoc:41

[source, python]
----
resp = client.indices.create(
index="my-index-000001",
body={
"settings": {
"index": {
"sort.field": ["username", "date"],
"sort.order": ["asc", "desc"],
}
},
"mappings": {
"properties": {
"username": {"type": "keyword", "doc_values": True},
"date": {"type": "date"},
}
},
},
)
print(resp)
----
10 changes: 10 additions & 0 deletions docs/examples/dad2d4add751fde5c39475ca709cc14b.asciidoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// index-modules/allocation/filtering.asciidoc:54

[source, python]
----
resp = client.indices.put_settings(
index="test",
body={"index.routing.allocation.include.size": "big,medium"},
)
print(resp)
----

0 comments on commit 3a1cd62

Please sign in to comment.