Create the new index test and put the data in it:
MapIndexed[
URLExecute@HTTPRequest[
<|
"Domain" -> "localhost", "Port" -> 9200,
"Path" -> {"test", "external", ToString[First@#2]}
|>,
<|
Method -> "PUT",
"Body" -> ExportString[<|"Text" -> #1|>, "PythonExpression", CharacterEncoding -> "Unicode"],
"ContentType" -> "application/json"
|>
] &,
(*DATA*){"abc", "def", "ghi"}
]
{{"_index" -> "test", "_type" -> "external", "_id" -> "1",
"_version" -> 1, "result" -> "created",
"_shards" -> {"total" -> 2, "successful" -> 1, "failed" -> 0},
"_seq_no" -> 0, "_primary_term" -> 1}, {"_index" -> "test",
"_type" -> "external", "_id" -> "2", "_version" -> 1,
"result" -> "created",
"_shards" -> {"total" -> 2, "successful" -> 1, "failed" -> 0},
"_seq_no" -> 1, "_primary_term" -> 1}, {"_index" -> "test",
"_type" -> "external", "_id" -> "3", "_version" -> 1,
"result" -> "created",
"_shards" -> {"total" -> 2, "successful" -> 1, "failed" -> 0},
"_seq_no" -> 2, "_primary_term" -> 1}}
Search:
URLExecute@HTTPRequest[
<|
"Domain" -> "localhost", "Port" -> 9200,
"Path" -> {"test", "_search"},
"Query" -> <|"q" -> "Text: g*"|>
|>,
<|Method -> "GET"|>
]
{"took" -> 1, "timed_out" -> False,
"_shards" -> {"total" -> 1, "successful" -> 1, "skipped" -> 0,
"failed" -> 0},
"hits" -> {"total" -> {"value" -> 1, "relation" -> "eq"},
"max_score" -> 1.,
"hits" -> {{"_index" -> "test", "_type" -> "external",
"_id" -> "3", "_score" -> 1., "_source" -> {"Text" -> "ghi"}}}}}
Delete document from index:
URLExecute@HTTPRequest[
<|
"Domain" -> "localhost", "Port" -> 9200,
"Path" -> {"test", "external", "3"}
|>,
<|Method -> "DELETE"|>
]
{"_index" -> "test", "_type" -> "external", "_id" -> "3",
"_version" -> 2, "result" -> "deleted",
"_shards" -> {"total" -> 2, "successful" -> 1, "failed" -> 0},
"_seq_no" -> 3, "_primary_term" -> 1}
Search again:
URLExecute@HTTPRequest[
<|
"Domain" -> "localhost", "Port" -> 9200,
"Path" -> {"test", "_search"},
"Query" -> <|"q" -> "Text: g*"|>
|>,
<|Method -> "GET"|>
]
{"took" -> 2, "timed_out" -> False,
"_shards" -> {"total" -> 1, "successful" -> 1, "skipped" -> 0,
"failed" -> 0},
"hits" -> {"total" -> {"value" -> 0, "relation" -> "eq"},
"max_score" -> Null, "hits" -> {}}}
Delete index:
URLExecute@HTTPRequest[
<|
"Domain" -> "localhost", "Port" -> 9200,
"Path" -> {"test"}
|>,
<|"Method" -> "DELETE"|>
]
{"acknowledged" -> True}