# How to write DtSearchConverter, NotSpanQuery in elastic?

**URL:** <https://discuss.elastic.co/t/how-to-write-dtsearchconverter-notspanquery-in-elastic/231823>\
**Category:** Elasticsearch\
**Created:** [May 9, 2020, 8:02am UTC](https://discuss.elastic.co/t/how-to-write-dtsearchconverter-notspanquery-in-elastic/231823 "2020-05-09T08:02:28Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Attila816](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/attila816/32/68007_2.png) [@Attila816](https://discuss.elastic.co/u/Attila816)\
**Post date:** [May 9, 2020, 8:02am UTC](https://discuss.elastic.co/t/how-to-write-dtsearchconverter-notspanquery-in-elastic/231823/1 "2020-05-09T08:02:28Z")

</div>

Hi,

how can I write NotSpanQuery which is not the same as SpanNotQuery in Elastic?

How can I write a query like this in elastic: `QueryA AND NOT QueryB`  
what I want to rewrite it as `QueryA NOT W/Integer.MAX_VALUE QueryB` ?

Also how can I write `QueryA OR NOT QueryB`  
what I want to write as `QueryA OR * NOT W/Integer.MAX_VALUE QueryB`?

Or if I have a proximity query like `QueryA w/50 NOT QueryB`  
how can I rewrite that as `QueryA w/50 (* w/Integer.MAX_VALUE QueryB)` - which is the same as OR NOT?

So generally what I would like to earn to create a [DtSearch Parser](https://github.com/blmille1/dtsearchparser/blob/master/Plugins/MillersoftSolrPlugins/src/com/millersoft/solr/parsers/dtsearch/DtSearchParser.java) with Elastic Queries?  
Do anyone has a kind of like that parser which can be shared with us? Or can help with sharing ideas on that?

I have seen a [plugin](https://github.com/blmille1/dtsearchparser) what can be used to create a DtSearch Parser but this is used for SolR with [Lucene Queries](https://github.com/blmille1/dtsearchparser/blob/master/Plugins/MillersoftSolrPlugins/src/com/millersoft/solr/parsers/dtsearch/DtSearchVisitor.java) and I would like use Elasticsearch with Nest Query Visitor and this is where I need Your help.

How can we use a visitor like that with Nest Queries?  
What are the elastic Query equivalents for the Lucene ones used in that visitor like [NotSpanQuery](https://github.com/blmille1/dtsearchparser/blob/master/Plugins/MillersoftSolrPlugins/src/com/millersoft/solr/parsers/dtsearch/NotSpanQuery.java)?

Thanks!

---

<div class="post-metadata">

**Author:** ![Attila816](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/attila816/32/68007_2.png) [@Attila816](https://discuss.elastic.co/u/Attila816)\
**Post date:** [May 12, 2020, 9:26am UTC](https://discuss.elastic.co/t/how-to-write-dtsearchconverter-notspanquery-in-elastic/231823/2 "2020-05-12T09:26:22Z")

</div>

I saw a topic in this community which is helpful for combining queries with Boolean Query:

- [Combining nested query with bool query](https://discuss.elastic.co/t/combining-nested-query-with-bool-query/94701)

Is there a way to see other examples like I mentioned above working as combining nested queries?

- QueryA AND NOT QueryB
- QueryA OR NOT QueryB
- QueryA w/50 NOT QueryB

Thanks

---

<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:** [June 9, 2020, 9:26am UTC](https://discuss.elastic.co/t/how-to-write-dtsearchconverter-notspanquery-in-elastic/231823/3 "2020-06-09T09:26:25Z")

</div>

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