1

私はelasticsearchのscalaとelastic4sで遊んで学んでいます。

公式のelasticsearchモジュールを使用するpythonスクリプトがあります。Python での私のコードは次のようになります。

res=helpers.scan(es, query={"_source": ["http_uri", "header_user_agent"],"query": {"query_string": {"query": "message:key"}}}, index="")

上記のpythonコードは機能します。900k の結果が得られ、それらを処理します。

基本的な scala コードを使用して e4s を試しています。これは単純なクエリです。私のクエリは間違っていますか?

import com.sksamuel.elastic4s.ElasticClient
import com.sksamuel.elastic4s.ElasticDsl._

object Banana {
    def main(args: Array[String]) {
        val client = ElasticClient.local

        val res = client execute { search in "*"  query "apiKey" } await

        println(res.getHits.totalHits)

        println(res)
    }
}

これを実行した結果:

info] Running Banana
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
0
{
  "took" : 1,
  "timed_out" : false,
  "_shards" : {
    "total" : 0,
    "successful" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : 0,
    "max_score" : 0.0,
    "hits" : [ ]
  }
}

そして、curl クエリによる応答:

$ curl -s 'localhost:9200/_search?q=apiKey&pretty=true' | head -12
{
  "took" : 21,
  "timed_out" : false,
  "_shards" : {
    "total" : 1200,
    "successful" : 1200,
    "failed" : 0
  },
  "hits" : {
    "total" : 756253,
    "max_score" : 1.5905869,
    "hits" : [ {
4

2 に答える 2

3

@chengpohiは、ローカルノードを作成していて、使用時にクラスターに接続していないことは正しいためval client = ElasticClient.local、使用する必要があります

val uri = ElasticsearchClientUri("elasticsearch://127.0.0.1:9300") 
val settings = ImmutableSettings.settingsBuilder().put("cluster.name", "myClusterName").build()
val client = ElasticClient.remote(settings, uri)

*しかし、さらに、あなたが思っているようにすべてのインデックスを意味するわけではないというインデックスを検索しています。すべてのインデックスで検索したい場合は、_allたとえば使用する必要があります

client execute { 
  search in "_all" query "findme" 
}
于 2015-03-18T22:26:52.863 に答える