Search code examples
elasticsearchelastic4s

elastic4s search for id


two questions regarding searching _id field:

  1. I want to find if specific id exists using elastic4s dsl. the aquivilent to this query elasticsearch API:

    curl -XGET 'http://localhost:9200/indexName/indexType/_search/exists?q=_id:foo'

I tried to do something like this :

 client execute search(indexName / indexType) query ("_id", "foo")

but this yields SearchDefinition which cannot be checked by isExists

  1. I want to fetch all _id's so far I got this solution but I am not sure that this is the idomatic way to do it

    client.execute(search(indexName / indexType) query "id").map(.ids)


Solution

  • You can query for id with the Ids Query https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-ids-query.html#query-dsl-ids-query

     search("electronics" / "phone").query(idsQuery("foo"))