我正在尝试从年龄(索引的字段)大于 50 的索引中删除文档。所以基本上我正在尝试编写范围查询。我已经从 Scala 成功连接到 ElasticSearch,而且我还可以删除整个索引。但我无法编写范围查询。有人可以帮我写一个范围查询,以从 scala 的索引中删除文档。下面是我删除整个索引的代码片段。我在 Java 中看到了很多示例,但我需要 SCALA 中的解决方案。
import com.sksamuel.elastic4s.delete.DeleteByQueryRequest
import org.apache.http.HttpHost
import org.apache.http.auth.{AuthScope, Credentials, UsernamePasswordCredentials}
import org.apache.http.client.CredentialsProvider
import org.apache.http.impl.client.BasicCredentialsProvider
import org.apache.http.impl.nio.client.HttpAsyncClientBuilder
import org.elasticsearch.client.RestClient
import org.elasticsearch.client.RestClientBuilder
System.setProperty("javax.net.ssl.trustStore", "path of certificate")
System.setProperty("javax.net.ssl.trustStorePassword", "password")
val credentials = new UsernamePasswordCredentials("username", "password");
val credentialsProvider:CredentialsProvider = new BasicCredentialsProvider
credentialsProvider.setCredentials(AuthScope.ANY, credentials)
val client = RestClient.builder(new HttpHost("host", 9200,"https")).setHttpClientConfigCallback(new RestClientBuilder.HttpClientConfigCallback() {
override def customizeHttpClient(httpClientBuilder: HttpAsyncClientBuilder): HttpAsyncClientBuilder = httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider)
}).build
// Delete entire index
val request = new Request("DELETE", "/products")
val response = client.performRequest(request)