Skip to content

Commit

Permalink
Add mapping python code examples (#2596)
Browse files Browse the repository at this point in the history
  • Loading branch information
anniegale9538 authored Jun 25, 2024
1 parent 9656f83 commit 5c9b470
Show file tree
Hide file tree
Showing 195 changed files with 4,243 additions and 0 deletions.
25 changes: 25 additions & 0 deletions docs/examples/033838729cfb5d1a28d04f69ee78d924.asciidoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// mapping/types/geo-shape.asciidoc:300

[source, python]
----
resp = client.index(
index="example",
body={
"location": {
"type": "Polygon",
"orientation": "LEFT",
"coordinates": [
[
[-177, 10],
[176, 15],
[172, 0],
[176, -15],
[-177, -10],
[-177, 10],
]
],
}
},
)
print(resp)
----
23 changes: 23 additions & 0 deletions docs/examples/05500e77aef581d92f6c605f7a48f7df.asciidoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// mapping/types/shape.asciidoc:199

[source, python]
----
resp = client.index(
index="example",
body={
"location": {
"type": "polygon",
"coordinates": [
[
[1000, -1001],
[1001, -1001],
[1001, -1000],
[1000, -1000],
[1000, -1001],
]
],
}
},
)
print(resp)
----
17 changes: 17 additions & 0 deletions docs/examples/07de76cb0e7f11c7533788faf8c093c3.asciidoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// mapping/types/flattened.asciidoc:205

[source, python]
----
resp = client.indices.create(
index="my-index-000001",
body={
"mappings": {
"properties": {
"title": {"type": "text"},
"labels": {"type": "flattened"},
}
}
},
)
print(resp)
----
27 changes: 27 additions & 0 deletions docs/examples/0b987b4101e016653a32d7b092d47e4c.asciidoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// mapping/types/object.asciidoc:46

[source, python]
----
resp = client.indices.create(
index="my-index-000001",
body={
"mappings": {
"properties": {
"region": {"type": "keyword"},
"manager": {
"properties": {
"age": {"type": "integer"},
"name": {
"properties": {
"first": {"type": "text"},
"last": {"type": "text"},
}
},
}
},
}
}
},
)
print(resp)
----
17 changes: 17 additions & 0 deletions docs/examples/0c2ca704a39dda8b3a7c5806ec6c6cf8.asciidoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// mapping/runtime.asciidoc:1379

[source, python]
----
resp = client.indices.put_mapping(
index="my-index-000001",
body={
"runtime": {
"http.client_ip": {
"type": "ip",
"script": "\n String clientip=grok('%{COMMONAPACHELOG}').extract(doc[\"message\"].value)?.clientip;\n if (clientip != null) emit(clientip); \n ",
}
}
},
)
print(resp)
----
28 changes: 28 additions & 0 deletions docs/examples/0db06c3cba57cf442ac7fab89966e1e1.asciidoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// mapping/types/parent-join.asciidoc:76

[source, python]
----
resp = client.index(
index="my-index-000001",
id="1",
refresh=True,
body={
"my_id": "1",
"text": "This is a question",
"my_join_field": "question",
},
)
print(resp)
resp = client.index(
index="my-index-000001",
id="2",
refresh=True,
body={
"my_id": "2",
"text": "This is another question",
"my_join_field": "question",
},
)
print(resp)
----
48 changes: 48 additions & 0 deletions docs/examples/0fb472645116d58ddef89ca976d15a01.asciidoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// mapping/runtime.asciidoc:471

[source, python]
----
resp = client.bulk(
index="my-index-000001",
refresh="true",
body=[
{"index": {}},
{
"@timestamp": 1516729294000,
"model_number": "QVKC92Q",
"measures": {"voltage": 5.2},
},
{"index": {}},
{
"@timestamp": 1516642894000,
"model_number": "QVKC92Q",
"measures": {"voltage": 5.8},
},
{"index": {}},
{
"@timestamp": 1516556494000,
"model_number": "QVKC92Q",
"measures": {"voltage": 5.1},
},
{"index": {}},
{
"@timestamp": 1516470094000,
"model_number": "QVKC92Q",
"measures": {"voltage": 5.6},
},
{"index": {}},
{
"@timestamp": 1516383694000,
"model_number": "HG537PU",
"measures": {"voltage": 4.2},
},
{"index": {}},
{
"@timestamp": 1516297294000,
"model_number": "HG537PU",
"measures": {"voltage": 4},
},
],
)
print(resp)
----
15 changes: 15 additions & 0 deletions docs/examples/100d4e33158069f3caa32e8bfa0eb3d0.asciidoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// mapping/runtime.asciidoc:175

[source, python]
----
resp = client.indices.create(
index="my-index-000001",
body={
"mappings": {
"dynamic": "runtime",
"properties": {"@timestamp": {"type": "date"}},
}
},
)
print(resp)
----
33 changes: 33 additions & 0 deletions docs/examples/10535507a9735fcf06600444b9067d4c.asciidoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// mapping/types/text.asciidoc:181

[source, python]
----
resp = client.indices.create(
index="idx",
body={
"mappings": {
"_source": {"mode": "synthetic"},
"properties": {
"text": {
"type": "text",
"fields": {"raw": {"type": "keyword"}},
}
},
}
},
)
print(resp)
resp = client.index(
index="idx",
id="1",
body={
"text": [
"the quick brown fox",
"the quick brown fox",
"jumped over the lazy dog",
]
},
)
print(resp)
----
30 changes: 30 additions & 0 deletions docs/examples/1233be1d4c9c7ca54126f1a0693b26de.asciidoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// mapping/types/parent-join.asciidoc:104

[source, python]
----
resp = client.index(
index="my-index-000001",
id="3",
routing="1",
refresh=True,
body={
"my_id": "3",
"text": "This is an answer",
"my_join_field": {"name": "answer", "parent": "1"},
},
)
print(resp)
resp = client.index(
index="my-index-000001",
id="4",
routing="1",
refresh=True,
body={
"my_id": "4",
"text": "This is another answer",
"my_join_field": {"name": "answer", "parent": "1"},
},
)
print(resp)
----
24 changes: 24 additions & 0 deletions docs/examples/14a49c13c399840e64c00b487aa820c9.asciidoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// mapping/types/date_nanos.asciidoc:160

[source, python]
----
resp = client.indices.create(
index="idx",
body={
"mappings": {
"_source": {"mode": "synthetic"},
"properties": {"date": {"type": "date_nanos"}},
}
},
)
print(resp)
resp = client.index(
index="idx",
id="1",
body={
"date": ["2015-01-01T12:10:30.000Z", "2014-01-01T12:10:30.000Z"]
},
)
print(resp)
----
15 changes: 15 additions & 0 deletions docs/examples/14afe65afee3d43f27aaaa5b37f26a31.asciidoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// mapping/types/geo-shape.asciidoc:165

[source, python]
----
resp = client.index(
index="example",
body={
"location": {
"type": "Point",
"coordinates": [-77.03653, 38.897676],
}
},
)
print(resp)
----
10 changes: 10 additions & 0 deletions docs/examples/14f124294a4a0e3a657d1468c36161cd.asciidoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// mapping/types/aggregate-metric-double.asciidoc:205

[source, python]
----
resp = client.search(
index="stats-index",
body={"query": {"term": {"agg_metric": {"value": 702.3}}}},
)
print(resp)
----
15 changes: 15 additions & 0 deletions docs/examples/154d703732daf5c5fcd0122e6a50213f.asciidoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// mapping/runtime.asciidoc:339

[source, python]
----
resp = client.indices.put_mapping(
index="my-index-000001",
body={
"runtime": {
"measures.start": {"type": "long"},
"measures.end": {"type": "long"},
}
},
)
print(resp)
----
20 changes: 20 additions & 0 deletions docs/examples/1572696b97822d3332be51700e09672f.asciidoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// mapping/types/range.asciidoc:130

[source, python]
----
resp = client.search(
index="range_index",
body={
"query": {
"range": {
"time_frame": {
"gte": "2015-10-31",
"lte": "2015-11-01",
"relation": "within",
}
}
}
},
)
print(resp)
----
10 changes: 10 additions & 0 deletions docs/examples/169b39bb889ecd47541bed3e48725488.asciidoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// mapping/types/flattened.asciidoc:73

[source, python]
----
resp = client.search(
index="bug_reports",
body={"query": {"term": {"labels": "urgent"}}},
)
print(resp)
----
Loading

0 comments on commit 5c9b470

Please sign in to comment.