Skip to content

Commit e3e109a

Browse files
authored
Create generator for Client Examples
1 parent 7f530d5 commit e3e109a

File tree

171 files changed

+2155
-63
lines changed

Some content is hidden

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

171 files changed

+2155
-63
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// docs/update.asciidoc:251
2+
3+
[source, python]
4+
----
5+
resp = client.update(
6+
index="test", id="1", body={"doc": {"name": "new_name"}, "detect_noop": False},
7+
)
8+
print(resp)
9+
----
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// aggregations/bucket/terms-aggregation.asciidoc:470
2+
3+
[source, python]
4+
----
5+
resp = client.search(
6+
body={
7+
"aggs": {
8+
"countries": {
9+
"terms": {
10+
"field": "artist.country",
11+
"order": [{"rock>playback_stats.avg": "desc"}, {"_count": "desc"}],
12+
},
13+
"aggs": {
14+
"rock": {
15+
"filter": {"term": {"genre": "rock"}},
16+
"aggs": {"playback_stats": {"stats": {"field": "play_count"}}},
17+
}
18+
},
19+
}
20+
}
21+
},
22+
)
23+
print(resp)
24+
----
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// aggregations/bucket/terms-aggregation.asciidoc:544
2+
3+
[source, python]
4+
----
5+
resp = client.search(
6+
body={
7+
"aggs": {
8+
"genres": {
9+
"terms": {
10+
"script": {"source": "doc['genre'].value", "lang": "painless"}
11+
}
12+
}
13+
}
14+
},
15+
)
16+
print(resp)
17+
----
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// query-dsl/multi-match-query.asciidoc:341
2+
3+
[source, python]
4+
----
5+
resp = client.search(
6+
body={
7+
"query": {
8+
"multi_match": {
9+
"query": "Will Smith",
10+
"type": "cross_fields",
11+
"fields": ["first_name", "last_name"],
12+
"operator": "and",
13+
}
14+
}
15+
},
16+
)
17+
print(resp)
18+
----
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// docs/index_.asciidoc:486
2+
3+
[source, python]
4+
----
5+
resp = client.create(
6+
index="twitter",
7+
id="1",
8+
body={
9+
"user": "kimchy",
10+
"post_date": "2009-11-15T14:12:12",
11+
"message": "trying out Elasticsearch",
12+
},
13+
)
14+
print(resp)
15+
----
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// query-dsl/bool-query.asciidoc:36
2+
3+
[source, python]
4+
----
5+
resp = client.search(
6+
body={
7+
"query": {
8+
"bool": {
9+
"must": {"term": {"user": "kimchy"}},
10+
"filter": {"term": {"tag": "tech"}},
11+
"must_not": {"range": {"age": {"gte": 10, "lte": 20}}},
12+
"should": [
13+
{"term": {"tag": "wow"}},
14+
{"term": {"tag": "elasticsearch"}},
15+
],
16+
"minimum_should_match": 1,
17+
"boost": 1,
18+
}
19+
}
20+
},
21+
)
22+
print(resp)
23+
----
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// indices/put-mapping.asciidoc:427
2+
3+
[source, python]
4+
----
5+
resp = client.index(index="users", refresh="wait_for", body={"user_id": 12345})
6+
print(resp)
7+
8+
resp = client.index(index="users", refresh="wait_for", body={"user_id": 12346})
9+
print(resp)
10+
----
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// query-dsl/match-all-query.asciidoc:11
2+
3+
[source, python]
4+
----
5+
resp = client.search(body={"query": {"match_all": {}}})
6+
print(resp)
7+
----
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// docs/update.asciidoc:271
2+
3+
[source, python]
4+
----
5+
resp = client.update(
6+
index="test",
7+
id="1",
8+
body={
9+
"script": {
10+
"source": "ctx._source.counter += params.count",
11+
"lang": "painless",
12+
"params": {"count": 4},
13+
},
14+
"upsert": {"counter": 1},
15+
},
16+
)
17+
print(resp)
18+
----
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// query-dsl/match-query.asciidoc:241
2+
3+
[source, python]
4+
----
5+
resp = client.search(
6+
body={
7+
"query": {
8+
"match": {
9+
"message": {
10+
"query": "to be or not to be",
11+
"operator": "and",
12+
"zero_terms_query": "all",
13+
}
14+
}
15+
}
16+
},
17+
)
18+
print(resp)
19+
----
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// aggregations/bucket/terms-aggregation.asciidoc:626
2+
3+
[source, python]
4+
----
5+
resp = client.search(
6+
body={
7+
"aggs": {
8+
"tags": {
9+
"terms": {
10+
"field": "tags",
11+
"include": ".*sport.*",
12+
"exclude": "water_.*",
13+
}
14+
}
15+
}
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+
// indices/put-mapping.asciidoc:166
2+
3+
[source, python]
4+
----
5+
resp = client.indices.put_mapping(
6+
index="my_index",
7+
body={"properties": {"name": {"properties": {"last": {"type": "text"}}}}},
8+
)
9+
print(resp)
10+
----
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// docs/reindex.asciidoc:20
2+
3+
[source, python]
4+
----
5+
resp = client.reindex(
6+
body={"source": {"index": "twitter"}, "dest": {"index": "new_twitter"}},
7+
)
8+
print(resp)
9+
----
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// search/request-body.asciidoc:92
2+
3+
[source, python]
4+
----
5+
resp = client.search(index="twitter", body={"query": {"term": {"user": "kimchy"}}})
6+
print(resp)
7+
----
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// query-dsl/multi-match-query.asciidoc:259
2+
3+
[source, python]
4+
----
5+
resp = client.search(
6+
body={
7+
"query": {
8+
"multi_match": {
9+
"query": "quick brown f",
10+
"type": "phrase_prefix",
11+
"fields": ["subject", "message"],
12+
}
13+
}
14+
},
15+
)
16+
print(resp)
17+
----
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// docs/reindex.asciidoc:699
2+
3+
[source, python]
4+
----
5+
resp = client.reindex(
6+
body={
7+
"source": {"index": "test"},
8+
"dest": {"index": "test2"},
9+
"script": {"source": 'ctx._source.tag = ctx._source.remove("flag")'},
10+
},
11+
)
12+
print(resp)
13+
----
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// indices/put-mapping.asciidoc:84
2+
3+
[source, python]
4+
----
5+
resp = client.indices.create(index="publications")
6+
print(resp)
7+
----
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// docs/reindex.asciidoc:687
2+
3+
[source, python]
4+
----
5+
resp = client.index(
6+
index="test", id="1", refresh=True, body={"text": "words words", "flag": "foo"},
7+
)
8+
print(resp)
9+
----
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// query-dsl/bool-query.asciidoc:130
2+
3+
[source, python]
4+
----
5+
resp = client.search(
6+
body={"query": {"constant_score": {"filter": {"term": {"status": "active"}}}}},
7+
)
8+
print(resp)
9+
----
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// search/search.asciidoc:400
2+
3+
[source, python]
4+
----
5+
resp = client.search(q="user:kimchy")
6+
print(resp)
7+
----
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// query-dsl/multi-match-query.asciidoc:472
2+
3+
[source, python]
4+
----
5+
resp = client.search(
6+
body={
7+
"query": {
8+
"multi_match": {
9+
"query": "Jon",
10+
"type": "cross_fields",
11+
"analyzer": "standard",
12+
"fields": ["first", "last", "*.edge"],
13+
}
14+
}
15+
},
16+
)
17+
print(resp)
18+
----
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// indices/put-mapping.asciidoc:346
2+
3+
[source, python]
4+
----
5+
resp = client.indices.put_mapping(
6+
index="my_index",
7+
body={"properties": {"user_id": {"type": "keyword", "ignore_above": 100}}},
8+
)
9+
print(resp)
10+
----
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// docs/reindex.asciidoc:191
2+
3+
[source, python]
4+
----
5+
resp = client.reindex(
6+
body={
7+
"source": {"index": "twitter", "slice": {"id": 0, "max": 2}},
8+
"dest": {"index": "new_twitter"},
9+
},
10+
)
11+
print(resp)
12+
13+
resp = client.reindex(
14+
body={
15+
"source": {"index": "twitter", "slice": {"id": 1, "max": 2}},
16+
"dest": {"index": "new_twitter"},
17+
},
18+
)
19+
print(resp)
20+
----
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// indices/templates.asciidoc:138
2+
3+
[source, python]
4+
----
5+
resp = client.indices.put_template(
6+
name="template_1",
7+
body={
8+
"index_patterns": ["te*"],
9+
"settings": {"number_of_shards": 1},
10+
"aliases": {
11+
"alias1": {},
12+
"alias2": {"filter": {"term": {"user": "kimchy"}}, "routing": "kimchy"},
13+
"{index}-alias": {},
14+
},
15+
},
16+
)
17+
print(resp)
18+
----
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// docs/reindex.asciidoc:802
2+
3+
[source, python]
4+
----
5+
resp = client.reindex(
6+
body={
7+
"max_docs": 10,
8+
"source": {
9+
"index": "twitter",
10+
"query": {"function_score": {"random_score": {}, "min_score": 0.9}},
11+
},
12+
"dest": {"index": "random_twitter"},
13+
},
14+
)
15+
print(resp)
16+
----

0 commit comments

Comments
 (0)