# Get documents based on some filter conditions

**URL:** <https://discuss.elastic.co/t/get-documents-based-on-some-filter-conditions/295431>\
**Category:** Elasticsearch\
**Tags:** es-hadoop\
**Created:** [January 26, 2022, 8:35am UTC](https://discuss.elastic.co/t/get-documents-based-on-some-filter-conditions/295431 "2022-01-26T08:35:41Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Khushboo\_Kaul](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/khushboo_kaul/32/100884_2.png) [@Khushboo\_Kaul](https://discuss.elastic.co/u/Khushboo_Kaul)\
**Post date:** [January 26, 2022, 8:35am UTC](https://discuss.elastic.co/t/get-documents-based-on-some-filter-conditions/295431/1 "2022-01-26T08:35:42Z")

</div>

Hi,  
I am trying to use spark ( pyspark) and my goal is to query from the huge Elasticsearch index a subset of data that matches a particular condition of column.  
For example, if my columns are - name, age, timestamp  
I want to get only those records where timestamp matches the current timestamp.

Could someone please assist on how to achieve this?

---

<div class="post-metadata">

**Author:** ![Keith\_Massey](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/keith_massey/32/83666_2.png) [@Keith\_Massey](https://discuss.elastic.co/u/Keith_Massey)\
**Post date:** [January 26, 2022, 11:50pm UTC](https://discuss.elastic.co/t/get-documents-based-on-some-filter-conditions/295431/2 "2022-01-26T23:50:26Z")

</div>

Hi @Khushboo_Kaul. The best way to get started is probably with spark-sql. One way is to create a temporary table from your index, and then run ordinary SQL queries on it:

```auto
from pyspark.sql import SQLContext
sqlContext = SQLContext(sc)
sqlContext.sql("CREATE TEMPORARY TABLE myTable USING org.elasticsearch.spark.sql OPTIONS (resource 'my_index')")
sqlContext.sql("select * from myTable").show()

```

Once you have that working you can add a where clause for the timestamp field like you would for any ordinary SQL query.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [February 25, 2022, 11:35am UTC](https://discuss.elastic.co/t/get-documents-based-on-some-filter-conditions/295431/4 "2022-02-25T11:35:19Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
