Skip to content

Commit 5c9b470

Browse files
Add mapping python code examples (#2596)
1 parent 9656f83 commit 5c9b470

File tree

195 files changed

+4243
-0
lines changed

Some content is hidden

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

195 files changed

+4243
-0
lines changed
+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// mapping/types/geo-shape.asciidoc:300
2+
3+
[source, python]
4+
----
5+
resp = client.index(
6+
index="example",
7+
body={
8+
"location": {
9+
"type": "Polygon",
10+
"orientation": "LEFT",
11+
"coordinates": [
12+
[
13+
[-177, 10],
14+
[176, 15],
15+
[172, 0],
16+
[176, -15],
17+
[-177, -10],
18+
[-177, 10],
19+
]
20+
],
21+
}
22+
},
23+
)
24+
print(resp)
25+
----
+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// mapping/types/shape.asciidoc:199
2+
3+
[source, python]
4+
----
5+
resp = client.index(
6+
index="example",
7+
body={
8+
"location": {
9+
"type": "polygon",
10+
"coordinates": [
11+
[
12+
[1000, -1001],
13+
[1001, -1001],
14+
[1001, -1000],
15+
[1000, -1000],
16+
[1000, -1001],
17+
]
18+
],
19+
}
20+
},
21+
)
22+
print(resp)
23+
----
+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// mapping/types/flattened.asciidoc:205
2+
3+
[source, python]
4+
----
5+
resp = client.indices.create(
6+
index="my-index-000001",
7+
body={
8+
"mappings": {
9+
"properties": {
10+
"title": {"type": "text"},
11+
"labels": {"type": "flattened"},
12+
}
13+
}
14+
},
15+
)
16+
print(resp)
17+
----
+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// mapping/types/object.asciidoc:46
2+
3+
[source, python]
4+
----
5+
resp = client.indices.create(
6+
index="my-index-000001",
7+
body={
8+
"mappings": {
9+
"properties": {
10+
"region": {"type": "keyword"},
11+
"manager": {
12+
"properties": {
13+
"age": {"type": "integer"},
14+
"name": {
15+
"properties": {
16+
"first": {"type": "text"},
17+
"last": {"type": "text"},
18+
}
19+
},
20+
}
21+
},
22+
}
23+
}
24+
},
25+
)
26+
print(resp)
27+
----
+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// mapping/runtime.asciidoc:1379
2+
3+
[source, python]
4+
----
5+
resp = client.indices.put_mapping(
6+
index="my-index-000001",
7+
body={
8+
"runtime": {
9+
"http.client_ip": {
10+
"type": "ip",
11+
"script": "\n String clientip=grok('%{COMMONAPACHELOG}').extract(doc[\"message\"].value)?.clientip;\n if (clientip != null) emit(clientip); \n ",
12+
}
13+
}
14+
},
15+
)
16+
print(resp)
17+
----
+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// mapping/types/parent-join.asciidoc:76
2+
3+
[source, python]
4+
----
5+
resp = client.index(
6+
index="my-index-000001",
7+
id="1",
8+
refresh=True,
9+
body={
10+
"my_id": "1",
11+
"text": "This is a question",
12+
"my_join_field": "question",
13+
},
14+
)
15+
print(resp)
16+
17+
resp = client.index(
18+
index="my-index-000001",
19+
id="2",
20+
refresh=True,
21+
body={
22+
"my_id": "2",
23+
"text": "This is another question",
24+
"my_join_field": "question",
25+
},
26+
)
27+
print(resp)
28+
----
+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// mapping/runtime.asciidoc:471
2+
3+
[source, python]
4+
----
5+
resp = client.bulk(
6+
index="my-index-000001",
7+
refresh="true",
8+
body=[
9+
{"index": {}},
10+
{
11+
"@timestamp": 1516729294000,
12+
"model_number": "QVKC92Q",
13+
"measures": {"voltage": 5.2},
14+
},
15+
{"index": {}},
16+
{
17+
"@timestamp": 1516642894000,
18+
"model_number": "QVKC92Q",
19+
"measures": {"voltage": 5.8},
20+
},
21+
{"index": {}},
22+
{
23+
"@timestamp": 1516556494000,
24+
"model_number": "QVKC92Q",
25+
"measures": {"voltage": 5.1},
26+
},
27+
{"index": {}},
28+
{
29+
"@timestamp": 1516470094000,
30+
"model_number": "QVKC92Q",
31+
"measures": {"voltage": 5.6},
32+
},
33+
{"index": {}},
34+
{
35+
"@timestamp": 1516383694000,
36+
"model_number": "HG537PU",
37+
"measures": {"voltage": 4.2},
38+
},
39+
{"index": {}},
40+
{
41+
"@timestamp": 1516297294000,
42+
"model_number": "HG537PU",
43+
"measures": {"voltage": 4},
44+
},
45+
],
46+
)
47+
print(resp)
48+
----
+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// mapping/runtime.asciidoc:175
2+
3+
[source, python]
4+
----
5+
resp = client.indices.create(
6+
index="my-index-000001",
7+
body={
8+
"mappings": {
9+
"dynamic": "runtime",
10+
"properties": {"@timestamp": {"type": "date"}},
11+
}
12+
},
13+
)
14+
print(resp)
15+
----
+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// mapping/types/text.asciidoc:181
2+
3+
[source, python]
4+
----
5+
resp = client.indices.create(
6+
index="idx",
7+
body={
8+
"mappings": {
9+
"_source": {"mode": "synthetic"},
10+
"properties": {
11+
"text": {
12+
"type": "text",
13+
"fields": {"raw": {"type": "keyword"}},
14+
}
15+
},
16+
}
17+
},
18+
)
19+
print(resp)
20+
21+
resp = client.index(
22+
index="idx",
23+
id="1",
24+
body={
25+
"text": [
26+
"the quick brown fox",
27+
"the quick brown fox",
28+
"jumped over the lazy dog",
29+
]
30+
},
31+
)
32+
print(resp)
33+
----
+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// mapping/types/parent-join.asciidoc:104
2+
3+
[source, python]
4+
----
5+
resp = client.index(
6+
index="my-index-000001",
7+
id="3",
8+
routing="1",
9+
refresh=True,
10+
body={
11+
"my_id": "3",
12+
"text": "This is an answer",
13+
"my_join_field": {"name": "answer", "parent": "1"},
14+
},
15+
)
16+
print(resp)
17+
18+
resp = client.index(
19+
index="my-index-000001",
20+
id="4",
21+
routing="1",
22+
refresh=True,
23+
body={
24+
"my_id": "4",
25+
"text": "This is another answer",
26+
"my_join_field": {"name": "answer", "parent": "1"},
27+
},
28+
)
29+
print(resp)
30+
----
+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// mapping/types/date_nanos.asciidoc:160
2+
3+
[source, python]
4+
----
5+
resp = client.indices.create(
6+
index="idx",
7+
body={
8+
"mappings": {
9+
"_source": {"mode": "synthetic"},
10+
"properties": {"date": {"type": "date_nanos"}},
11+
}
12+
},
13+
)
14+
print(resp)
15+
16+
resp = client.index(
17+
index="idx",
18+
id="1",
19+
body={
20+
"date": ["2015-01-01T12:10:30.000Z", "2014-01-01T12:10:30.000Z"]
21+
},
22+
)
23+
print(resp)
24+
----
+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// mapping/types/geo-shape.asciidoc:165
2+
3+
[source, python]
4+
----
5+
resp = client.index(
6+
index="example",
7+
body={
8+
"location": {
9+
"type": "Point",
10+
"coordinates": [-77.03653, 38.897676],
11+
}
12+
},
13+
)
14+
print(resp)
15+
----
+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// mapping/types/aggregate-metric-double.asciidoc:205
2+
3+
[source, python]
4+
----
5+
resp = client.search(
6+
index="stats-index",
7+
body={"query": {"term": {"agg_metric": {"value": 702.3}}}},
8+
)
9+
print(resp)
10+
----
+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// mapping/runtime.asciidoc:339
2+
3+
[source, python]
4+
----
5+
resp = client.indices.put_mapping(
6+
index="my-index-000001",
7+
body={
8+
"runtime": {
9+
"measures.start": {"type": "long"},
10+
"measures.end": {"type": "long"},
11+
}
12+
},
13+
)
14+
print(resp)
15+
----
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// mapping/types/range.asciidoc:130
2+
3+
[source, python]
4+
----
5+
resp = client.search(
6+
index="range_index",
7+
body={
8+
"query": {
9+
"range": {
10+
"time_frame": {
11+
"gte": "2015-10-31",
12+
"lte": "2015-11-01",
13+
"relation": "within",
14+
}
15+
}
16+
}
17+
},
18+
)
19+
print(resp)
20+
----
+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// mapping/types/flattened.asciidoc:73
2+
3+
[source, python]
4+
----
5+
resp = client.search(
6+
index="bug_reports",
7+
body={"query": {"term": {"labels": "urgent"}}},
8+
)
9+
print(resp)
10+
----

0 commit comments

Comments
 (0)