# Specify es.query condition in HIVE SQL query?

**URL:** https://discuss.elastic.co/t/specify-es-query-condition-in-hive-sql-query/47178
**Category:** Elasticsearch
**Tags:** es-hadoop
**Created:** [April 13, 2016, 1:37am UTC](https://discuss.elastic.co/t/specify-es-query-condition-in-hive-sql-query/47178 "2016-04-13T01:37:03Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![andrewwwooster](https://avatars.discourse-cdn.com/v4/letter/a/da6949/32.png) [@andrewwwooster](https://discuss.elastic.co/u/andrewwwooster)
#### Post date: [April 13, 2016, 1:37am UTC](https://discuss.elastic.co/t/specify-es-query-condition-in-hive-sql-query/47178/1 "2016-04-13T01:37:03Z")

</div>

Is it possible to pass the es.query parameter as part of a HIVE SQL query?

I currently specify the es.query query string as table property when I define an external table DDL:

```auto
CREATE EXTERNAL TABLE doc (
    url STRING,
    content_text ARRAY<STRING>
)
STORED BY 'org.elasticsearch.hadoop.hive.EsStorageHandler'
TBLPROPERTIES(
    'es.query' = '?q=desmoplastic',
    'es.port' = '11100', 
    'es.resource' = 'my_index/doc'
);

```

What I would really would like to do is be able to specify different es.query criteria for each SQL query, rather than having to create a new external table for each criteria. Something like this:

```auto
  select * 
  from doc
  where es.query = '?q=desmoplastic';

```

---

<div class="post-metadata">

### Author: ![costin](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/costin/32/44950_2.png) [@costin](https://discuss.elastic.co/u/costin)
#### Post date: [April 13, 2016, 12:01pm UTC](https://discuss.elastic.co/t/specify-es-query-condition-in-hive-sql-query/47178/2 "2016-04-13T12:01:59Z")

</div>

No, it is not; Hive SQL is not extendable.

Creating other tables for your queries is not that difficult; I would even argue it's the _right thing to do_ (tm) since SQL is all about references and by creating a different external table, you are basically creating a view/query alias.  
Which is easily supported and understood.

---

<div class="post-metadata">

### Author: ![andrewwwooster](https://avatars.discourse-cdn.com/v4/letter/a/da6949/32.png) [@andrewwwooster](https://discuss.elastic.co/u/andrewwwooster)
#### Post date: [April 13, 2016, 1:23pm UTC](https://discuss.elastic.co/t/specify-es-query-condition-in-hive-sql-query/47178/3 "2016-04-13T13:23:39Z")

</div>

Let me describe my use case a little more. I am working on integration between visual analytics tools like Tableau and Spotfire with ES. In a typical scenario, a user would perform a keyword search (with all of the benefits of the es analyzer, such as stemming, etc) to narrow 25M documents down to 100k, and then use Tableau or Spotfire to explore the results via SQL queries. Creating new external tables (i.e. view/query alias) for each query does not seem feasible.

If Hive is not extendable, would Spark be a better option?

---

<div class="post-metadata">

### Author: ![costin](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/costin/32/44950_2.png) [@costin](https://discuss.elastic.co/u/costin)
#### Post date: [April 13, 2016, 4:06pm UTC](https://discuss.elastic.co/t/specify-es-query-condition-in-hive-sql-query/47178/4 "2016-04-13T16:06:37Z")

</div>

I'm afraid Spark won't help as well. Both APIs provide SQL interfaces - specifying Lucene or custom queries goes beyond that. I'm not sure whether Tableau or Spotfire allow this either.

Note that one advantage Spark SQL has provides hooks so that ES-Hadoop can push down some operations. Thus one can start with a ES query, apply SQL on top of it and all of them would be assembled in the end.

---

<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: [July 6, 2017, 1:25pm UTC](https://discuss.elastic.co/t/specify-es-query-condition-in-hive-sql-query/47178/5 "2017-07-06T13:25:06Z")

</div>


