I'm trying to query elasticsearch with the elasticsearch-spark connector and I want to return only few results:
For example:
val conf = new SparkConf().set("es.nodes","localhost").set("es.index.auto.create", "true").setMaster("local")
val sparkContext = new SparkContext(conf)
val query = "{\"size\":1}"
println(sparkContext.esRDD("index_name/type", query).count())
However this will return all the documents in the index.
If I understand this correctly, you are executing a count operation, which does not return any documents. Do you expect it to return
1because you specifiedsize: 1? That's not happening, which is by design.Edited to add: This is the definition of
count()in elasticsearch-hadoop:It does not take the query into account at all, but considers the entire ES index as the RDD input.