【发布时间】:2020-09-16 11:37:19
【问题描述】:
我是 scala 和 elasticsearch 的新手。我在弹性搜索中有以下数据,索引名称=“abc”和文档类型=“_doc”。
{
"took": 45,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"skipped": 0,
"failed": 0
},
"hits": {
"total": 1,
"max_score": 1,
"hits": [
{
"_index": "abc",
"_type": "_doc",
"_id": "1234",
"_score": 1,
"_source": {
"Code": "PDF",
"Description": "Portion Occured",
"Id": "1234",
"Operator": {
"Id": "1",
"PopulationLevel": "Key"
},
"Usage": [
{
"Allow": true
}
]
}
}
]
}
}
我的弹性搜索客户端中有以下代码。
trait ElasticsearchClient {
lazy val esRestConnection: RestClient = createEsRestClient(elasticSearchsUri, elasticSearchProtocol)
lazy val esHttpConnection: HttpClient = HttpClient.fromRestClient(esRestConnection)
* Method to create instance of HTTP Client to access the given Elasticsearch URI.
def createEsRestClient(uri: String, protocol: String): RestClient = {
val hosts = ElasticsearchClientUri(uri).hosts.map {
case (host, port) =>
new HttpHost(host, port, protocol)
}
RestClient.builder(hosts: _*)
.build()
}
}
我正在使用 sksamuel elastic4s - Elasticsearch Scala 客户端
我需要编写一个代码,通过它我可以检索该特定索引的“Id”值,即 1234。我还有一些索引,我需要从弹性搜索中检索“Id”的值。我需要从我的代码中传递索引名称。我该怎么做呢
【问题讨论】:
标签: scala elasticsearch