Skip to content

Commit

Permalink
[Backport 8.14] adding index module code examples (#2559)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
3 people committed Jun 6, 2024
1 parent 728c616 commit 0ecc91b
Show file tree
Hide file tree
Showing 80 changed files with 599 additions and 173 deletions.
2 changes: 1 addition & 1 deletion docs/examples/00fea15cbca83be9d5f1a024ff2ec708.asciidoc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// inference/put-inference.asciidoc:275
// inference/put-inference.asciidoc:452

[source, python]
----
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/0e5db64154a722a5cbdb84b588ce2ce8.asciidoc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// mapping/types/numeric.asciidoc:275
// mapping/types/numeric.asciidoc:287

[source, python]
----
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/10c3fe2265bb34964bd1005f9da66773.asciidoc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// inference/put-inference.asciidoc:369
// inference/put-inference.asciidoc:559

[source, python]
----
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/13ecdf99114098c76b050397d9c3d4e6.asciidoc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// inference/post-inference.asciidoc:73
// inference/post-inference.asciidoc:197

[source, python]
----
Expand Down
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)
----
19 changes: 0 additions & 19 deletions docs/examples/197dc41c8df9629e145b3064c63b2ccc.asciidoc

This file was deleted.

2 changes: 1 addition & 1 deletion docs/examples/1aa91d3d48140d6367b6cabca8737b8f.asciidoc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// docs/bulk.asciidoc:634
// docs/bulk.asciidoc:632

[source, python]
----
Expand Down
19 changes: 19 additions & 0 deletions docs/examples/1dadb7efe27b6c0c231eb6535e413bd9.asciidoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// inference/put-inference.asciidoc:671

[source, python]
----
resp = client.inference.put_model(
task_type="text_embedding",
inference_id="azure_ai_studio_embeddings",
body={
"service": "azureaistudio",
"service_settings": {
"api_key": "<api_key>",
"target": "<target_uri>",
"provider": "<model_provider>",
"endpoint_type": "<endpoint_type>",
},
},
)
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)
----
2 changes: 1 addition & 1 deletion docs/examples/316cd43feb3b86396483903af1a048b1.asciidoc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// aggregations/bucket/datehistogram-aggregation.asciidoc:781
// aggregations/bucket/datehistogram-aggregation.asciidoc:782

[source, python]
----
Expand Down
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)
----
2 changes: 1 addition & 1 deletion docs/examples/3541d4a85e27b2c3896a7a7ee98b4b37.asciidoc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// health/health.asciidoc:478
// health/health.asciidoc:481

[source, python]
----
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/36063ff9a318dba7bb0be3a230655dc8.asciidoc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// mapping/types/numeric.asciidoc:247
// mapping/types/numeric.asciidoc:259

[source, python]
----
Expand Down
10 changes: 0 additions & 10 deletions docs/examples/36b86b97feedcf5632824eefc251d6ed.asciidoc

This file was deleted.

7 changes: 0 additions & 7 deletions docs/examples/3d1ff6097e2359f927c88c2ccdb36252.asciidoc

This file was deleted.

10 changes: 0 additions & 10 deletions docs/examples/3f3b3e207f79303ce6f86e03e928e062.asciidoc

This file was deleted.

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)
----
2 changes: 1 addition & 1 deletion docs/examples/4ca15672fc5ab1d80a127d086b6d2837.asciidoc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// cluster/allocation-explain.asciidoc:342
// cluster/allocation-explain.asciidoc:344

[source, python]
----
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/4e3414fc712b16311f9e433dd366f49d.asciidoc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// inference/delete-inference.asciidoc:53
// inference/delete-inference.asciidoc:55

[source, python]
----
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/51b40610ae05730b4c6afd25647d7ae0.asciidoc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// aggregations/bucket/datehistogram-aggregation.asciidoc:488
// aggregations/bucket/datehistogram-aggregation.asciidoc:489

[source, python]
----
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/5203560189ccab7122c03500147701ef.asciidoc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// aggregations/bucket/datehistogram-aggregation.asciidoc:568
// aggregations/bucket/datehistogram-aggregation.asciidoc:569

[source, python]
----
Expand Down
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)
----
2 changes: 1 addition & 1 deletion docs/examples/5553cf7a02c22f616cd994747f2dd5a5.asciidoc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// mapping/types/nested.asciidoc:58
// mapping/types/nested.asciidoc:60

[source, python]
----
Expand Down
17 changes: 17 additions & 0 deletions docs/examples/59d736a4d064ed2013c7ead8e32e0998.asciidoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// inference/put-inference.asciidoc:600

[source, python]
----
resp = client.inference.put_model(
task_type="completion",
inference_id="openai-completion",
body={
"service": "openai",
"service_settings": {
"api_key": "<api_key>",
"model_id": "gpt-3.5-turbo",
},
},
)
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)
----
2 changes: 1 addition & 1 deletion docs/examples/6cd083045bf06e80b83889a939a18451.asciidoc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// mapping/types/nested.asciidoc:85
// mapping/types/nested.asciidoc:87

[source, python]
----
Expand Down
Loading

0 comments on commit 0ecc91b

Please sign in to comment.