1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146
|
// This file is autogenerated, DO NOT EDIT
// search/search-your-data/retrievers-examples.asciidoc:14
[source, python]
----
resp = client.indices.create(
index="retrievers_example",
settings={
"number_of_shards": 1
},
mappings={
"properties": {
"vector": {
"type": "dense_vector",
"dims": 3,
"similarity": "l2_norm",
"index": True,
"index_options": {
"type": "flat"
}
},
"text": {
"type": "text"
},
"year": {
"type": "integer"
},
"topic": {
"type": "keyword"
},
"timestamp": {
"type": "date"
}
}
},
)
print(resp)
resp1 = client.index(
index="retrievers_example",
id="1",
document={
"vector": [
0.23,
0.67,
0.89
],
"text": "Large language models are revolutionizing information retrieval by boosting search precision, deepening contextual understanding, and reshaping user experiences in data-rich environments.",
"year": 2024,
"topic": [
"llm",
"ai",
"information_retrieval"
],
"timestamp": "2021-01-01T12:10:30"
},
)
print(resp1)
resp2 = client.index(
index="retrievers_example",
id="2",
document={
"vector": [
0.12,
0.56,
0.78
],
"text": "Artificial intelligence is transforming medicine, from advancing diagnostics and tailoring treatment plans to empowering predictive patient care for improved health outcomes.",
"year": 2023,
"topic": [
"ai",
"medicine"
],
"timestamp": "2022-01-01T12:10:30"
},
)
print(resp2)
resp3 = client.index(
index="retrievers_example",
id="3",
document={
"vector": [
0.45,
0.32,
0.91
],
"text": "AI is redefining security by enabling advanced threat detection, proactive risk analysis, and dynamic defenses against increasingly sophisticated cyber threats.",
"year": 2024,
"topic": [
"ai",
"security"
],
"timestamp": "2023-01-01T12:10:30"
},
)
print(resp3)
resp4 = client.index(
index="retrievers_example",
id="4",
document={
"vector": [
0.34,
0.21,
0.98
],
"text": "Elastic introduces Elastic AI Assistant, the open, generative AI sidekick powered by ESRE to democratize cybersecurity and enable users of every skill level.",
"year": 2023,
"topic": [
"ai",
"elastic",
"assistant"
],
"timestamp": "2024-01-01T12:10:30"
},
)
print(resp4)
resp5 = client.index(
index="retrievers_example",
id="5",
document={
"vector": [
0.11,
0.65,
0.47
],
"text": "Learn how to spin up a deployment of our hosted Elasticsearch Service and use Elastic Observability to gain deeper insight into the behavior of your applications and systems.",
"year": 2024,
"topic": [
"documentation",
"observability",
"elastic"
],
"timestamp": "2025-01-01T12:10:30"
},
)
print(resp5)
resp6 = client.indices.refresh(
index="retrievers_example",
)
print(resp6)
----
|