Skip to content

Commit 0ecc91b

Browse files
github-actions[bot]anniegale9538pquentin
authored
[Backport 8.14] adding index module code examples (#2559)
* adding index module code examples (#2554) * adding index module code examples * adding trailing comma (cherry picked from commit 3a1cd62) * Run examples generation again --------- Co-authored-by: Annie Hansen <annie.gale@elastic.co> Co-authored-by: Quentin Pradet <quentin.pradet@elastic.co>
1 parent 728c616 commit 0ecc91b

File tree

80 files changed

+599
-173
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

80 files changed

+599
-173
lines changed

docs/examples/00fea15cbca83be9d5f1a024ff2ec708.asciidoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// inference/put-inference.asciidoc:275
1+
// inference/put-inference.asciidoc:452
22

33
[source, python]
44
----

docs/examples/0e5db64154a722a5cbdb84b588ce2ce8.asciidoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// mapping/types/numeric.asciidoc:275
1+
// mapping/types/numeric.asciidoc:287
22

33
[source, python]
44
----

docs/examples/10c3fe2265bb34964bd1005f9da66773.asciidoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// inference/put-inference.asciidoc:369
1+
// inference/put-inference.asciidoc:559
22

33
[source, python]
44
----

docs/examples/13ecdf99114098c76b050397d9c3d4e6.asciidoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// inference/post-inference.asciidoc:73
1+
// inference/post-inference.asciidoc:197
22

33
[source, python]
44
----
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+
----

docs/examples/197dc41c8df9629e145b3064c63b2ccc.asciidoc

Lines changed: 0 additions & 19 deletions
This file was deleted.

docs/examples/1aa91d3d48140d6367b6cabca8737b8f.asciidoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// docs/bulk.asciidoc:634
1+
// docs/bulk.asciidoc:632
22

33
[source, python]
44
----
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// inference/put-inference.asciidoc:671
2+
3+
[source, python]
4+
----
5+
resp = client.inference.put_model(
6+
task_type="text_embedding",
7+
inference_id="azure_ai_studio_embeddings",
8+
body={
9+
"service": "azureaistudio",
10+
"service_settings": {
11+
"api_key": "<api_key>",
12+
"target": "<target_uri>",
13+
"provider": "<model_provider>",
14+
"endpoint_type": "<endpoint_type>",
15+
},
16+
},
17+
)
18+
print(resp)
19+
----
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+
----

docs/examples/316cd43feb3b86396483903af1a048b1.asciidoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// aggregations/bucket/datehistogram-aggregation.asciidoc:781
1+
// aggregations/bucket/datehistogram-aggregation.asciidoc:782
22

33
[source, python]
44
----
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+
----

docs/examples/3541d4a85e27b2c3896a7a7ee98b4b37.asciidoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// health/health.asciidoc:478
1+
// health/health.asciidoc:481
22

33
[source, python]
44
----

docs/examples/36063ff9a318dba7bb0be3a230655dc8.asciidoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// mapping/types/numeric.asciidoc:247
1+
// mapping/types/numeric.asciidoc:259
22

33
[source, python]
44
----

docs/examples/36b86b97feedcf5632824eefc251d6ed.asciidoc

Lines changed: 0 additions & 10 deletions
This file was deleted.

docs/examples/3d1ff6097e2359f927c88c2ccdb36252.asciidoc

Lines changed: 0 additions & 7 deletions
This file was deleted.

docs/examples/3f3b3e207f79303ce6f86e03e928e062.asciidoc

Lines changed: 0 additions & 10 deletions
This file was deleted.
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+
----

docs/examples/4ca15672fc5ab1d80a127d086b6d2837.asciidoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// cluster/allocation-explain.asciidoc:342
1+
// cluster/allocation-explain.asciidoc:344
22

33
[source, python]
44
----

docs/examples/4e3414fc712b16311f9e433dd366f49d.asciidoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// inference/delete-inference.asciidoc:53
1+
// inference/delete-inference.asciidoc:55
22

33
[source, python]
44
----

docs/examples/51b40610ae05730b4c6afd25647d7ae0.asciidoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// aggregations/bucket/datehistogram-aggregation.asciidoc:488
1+
// aggregations/bucket/datehistogram-aggregation.asciidoc:489
22

33
[source, python]
44
----

docs/examples/5203560189ccab7122c03500147701ef.asciidoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// aggregations/bucket/datehistogram-aggregation.asciidoc:568
1+
// aggregations/bucket/datehistogram-aggregation.asciidoc:569
22

33
[source, python]
44
----
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+
----

docs/examples/5553cf7a02c22f616cd994747f2dd5a5.asciidoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// mapping/types/nested.asciidoc:58
1+
// mapping/types/nested.asciidoc:60
22

33
[source, python]
44
----
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// inference/put-inference.asciidoc:600
2+
3+
[source, python]
4+
----
5+
resp = client.inference.put_model(
6+
task_type="completion",
7+
inference_id="openai-completion",
8+
body={
9+
"service": "openai",
10+
"service_settings": {
11+
"api_key": "<api_key>",
12+
"model_id": "gpt-3.5-turbo",
13+
},
14+
},
15+
)
16+
print(resp)
17+
----
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+
----

docs/examples/6cd083045bf06e80b83889a939a18451.asciidoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// mapping/types/nested.asciidoc:85
1+
// mapping/types/nested.asciidoc:87
22

33
[source, python]
44
----

0 commit comments

Comments
 (0)