# Please help me with this query

**URL:** https://discuss.elastic.co/t/please-help-me-with-this-query/4398
**Category:** Elasticsearch
**Created:** [May 13, 2011, 9:48am UTC](https://discuss.elastic.co/t/please-help-me-with-this-query/4398 "2011-05-13T09:48:25Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Jens\_vdH](https://avatars.discourse-cdn.com/v4/letter/j/ee59a6/32.png) [@Jens\_vdH](https://discuss.elastic.co/u/Jens_vdH)
#### Post date: [May 13, 2011, 9:48am UTC](https://discuss.elastic.co/t/please-help-me-with-this-query/4398/1 "2011-05-13T09:48:25Z")

</div>

Hi,

I'm quite new to elasticsearch and that's why I could need a little help with a query I'm working on.  
I need to combine an AND filter with an OR filter, but dont know how to do that.

My Data looks something like this:

{  
"metadata" :  
[  
"value\_A" : "something",  
"access\_A" : "2",  
"value\_B" : "else",  
"access\_B" : "0"  
]  
}

In SQL I would do something like this:

select \* from xxx where  
(metadata.value\_A = "something" AND metadata.access\_A = 2")  
OR  
(metadata.value\_B = "something" AND metadata.access\_B = 2")

So I'd like to search 2-x VALUE-Fields for a specific term that HAVE to have a specific access-ID.  
Value has to match, Access has to be a specific ID too. Only if both match, it should produce a result.  
How would I do that with elasticsearch. The only thing that came to my mind is by using a Script-Filter.

Cheers,  
Jens

--  
Registergericht: Amtsgericht Köln HRB 63609  
USt-Nr.: 214 5814 2930

* * *

## ::: ANGEKLICKT - MIT PIETZPLUSWILD INS WEB :::

++ Alumniportal Deutschland || Guided Tour  
-\> [www.alumniportal-deutschland.org](http://www.alumniportal-deutschland.org)

++ Tremco illbruck International GmbH || Design und Animation  
-\> [www.tremco-illbruck.com](http://www.tremco-illbruck.com)

++ Aktuelles im Blick || Agentur- News und Projekte  
-\> [www.pietzpluswild.de](http://www.pietzpluswild.de)

===  
Die Information in dieser E-Mail ist ausschliesslich fuer den Adressaten bestimmt und koennte vertrauliches und/oder privilegiertes Material enthalten. Jeglicher Zugriff auf diese E-Mail, die Übertragung, die Verbreitung oder anderweitige Verwendung sowie die Ergreifung von Massnahmen irgendeiner Art durch andere Personen als den Adressaten sind untersagt. Sollten Sie diese E-Mail irrtuemlich erhalten haben, informieren Sie bitte unverzüglich den Absender und löschen Sie diese E-Mail von Ihrem Computer, ohne Kopien anzufertigen.

Wir korrespondieren mit Ihnen ueber das Internet per E-Mail. Dennoch ist allein die von uns unterzeichnete schriftliche Fassung verbindlich. Wir weisen darauf hin, dass E-Mails verloren gehen, veraendert oder verfaelscht werden koennen. E-Mails sind grundsätzlich nicht gegen den Zugriff von Dritten geschuetzt. Daher ist auch die Vertraulichkeit unter Umstaenden nicht gewahrt. Wir haften deshalb nicht fuer die Unversehrtheit von E-Mails, nachdem sie unseren Herrschaftsbereich verlassen haben, und koennen Ihnen hieraus entstehende Schaeden nicht ersetzen. Sollte trotz der von uns verwendeten Viren-Schutz-Programme durch die Zusendung von E-Mails ein Virus in Ihre Systeme gelangen, haften wir nicht fuer eventuell hieraus entstehende Schaeden. Dieser Haftungsausschluss gilt nur soweit gesetzlich zulaessig.

---

<div class="post-metadata">

### Author: ![js1](https://avatars.discourse-cdn.com/v4/letter/j/51bf81/32.png) [@js1](https://discuss.elastic.co/u/js1)
#### Post date: [May 16, 2011, 1:40pm UTC](https://discuss.elastic.co/t/please-help-me-with-this-query/4398/2 "2011-05-16T13:40:26Z")

</div>

Hi,

try something like this:

{  
"query":{  
"ConstantScoreQuery":{  
"filter":{  
"or":[{  
"and":[{"term":{"":""}},{"term":{"":""}}]  
},{  
"and":[{"term":{"":""}},{"term":{"":""}}]  
}]  
}  
}  
}  
}

---

<div class="post-metadata">

### Author: ![Karussell1](https://avatars.discourse-cdn.com/v4/letter/k/50afbb/32.png) [@Karussell1](https://discuss.elastic.co/u/Karussell1)
#### Post date: [May 16, 2011, 5:11pm UTC](https://discuss.elastic.co/t/please-help-me-with-this-query/4398/3 "2011-05-16T17:11:49Z")

</div>

What do you want to achieve?

Using " within the enclosing brackets is not allowed in json. You'll  
need to escape it.

- take a look into the docs:

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

On May 16, 3:40 pm, js [js\_0...@yahoo.de](mailto:js_0...@yahoo.de) wrote:

> Hi,
> 
> try something like this:
> 
> {  
> "query":{  
> "ConstantScoreQuery":{  
> "filter":{  
> "or":[{  
> "and":[{"term":{"":""}},{"term":{"":""}}]  
> },{  
> "and":[{"term":{"":""}},{"term":{"":""}}]  
> }]  
> }  
> }  
> }
> 
> }
> 
> --  
> View this message in context:[http://elasticsearch-users.115913.n3.nabble.com/Please-help-me-with-t](http://elasticsearch-users.115913.n3.nabble.com/Please-help-me-with-t)...  
> Sent from the Elasticsearch Users mailing list archive at [Nabble.com](http://Nabble.com).

---

<div class="post-metadata">

### Author: ![js1](https://avatars.discourse-cdn.com/v4/letter/j/51bf81/32.png) [@js1](https://discuss.elastic.co/u/js1)
#### Post date: [May 17, 2011, 12:50pm UTC](https://discuss.elastic.co/t/please-help-me-with-this-query/4398/4 "2011-05-17T12:50:27Z")

</div>

Didn't mean to provide the entire script that is why I left the key value pairs left... I know that I need to escape them...

---

<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, 4:05am UTC](https://discuss.elastic.co/t/please-help-me-with-this-query/4398/5 "2017-07-06T04:05:59Z")

</div>


