# Query implementation

**URL:** <https://discuss.elastic.co/t/query-implementation/67520>\
**Category:** Elasticsearch\
**Created:** [November 29, 2016, 4:48pm UTC](https://discuss.elastic.co/t/query-implementation/67520 "2016-11-29T16:48:38Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![yr100](https://avatars.discourse-cdn.com/v4/letter/y/4da419/32.png) [@yr100](https://discuss.elastic.co/u/yr100)\
**Post date:** [November 29, 2016, 4:48pm UTC](https://discuss.elastic.co/t/query-implementation/67520/1 "2016-11-29T16:48:38Z")

</div>

I am trying to translate my query language to ES. I have the following operators  
AND, OR, NEAR, and NOT and I want to use any combination of them.

For example:  
NOT A  
NOT A\*  
(A OR B\*) NEAR (C OR "D E")  
NOT A OR NOT B  
etc.

Using Span\* I can implement AND OR and NEAR, but not NOT, however using bool I can implement  
NOT

Any idea?

Thanks

---

<div class="post-metadata">

**Author:** ![mvg](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mvg/32/98890_2.png) [@mvg](https://discuss.elastic.co/u/mvg)\
**Post date:** [November 30, 2016, 1:02pm UTC](https://discuss.elastic.co/t/query-implementation/67520/2 "2016-11-30T13:02:02Z")

</div>

The `bool` query can do both NOT (`must_not` clause), OR (`should` clause) and AND (`must` clause). For NEAR you can use `span_near` or `match_phrase` queries that you can then wrap into a `bool` query.

The `bool` query should be your main query as it allows you to add a clause (containing a `term`, `range`, `wildcard`, `match_phrase` and many other subqueries). The `bool` query is the glue that allows combining many queries.

---

<div class="post-metadata">

**Author:** ![yr100](https://avatars.discourse-cdn.com/v4/letter/y/4da419/32.png) [@yr100](https://discuss.elastic.co/u/yr100)\
**Post date:** [November 30, 2016, 9:47pm UTC](https://discuss.elastic.co/t/query-implementation/67520/3 "2016-11-30T21:47:38Z")

</div>

Thanks,  
I have problem with the proposed solution.

To translate the query (A OR B) NEAR (C OR D) - Span\* can do the job, and I can not use bool for NEAR. However, to implement (NOT A) the best solution is to use bool. The main problem is that span\_\* does not accept bool queries.

Is there a way to implement (NOT term) with span\_\*?

---

<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:** [December 28, 2016, 9:48pm UTC](https://discuss.elastic.co/t/query-implementation/67520/4 "2016-12-28T21:48:10Z")

</div>

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