# How do I make an OR query with keywords using multiple fields?

**URL:** <https://discuss.elastic.co/t/how-do-i-make-an-or-query-with-keywords-using-multiple-fields/4918>\
**Category:** Elasticsearch\
**Created:** [July 21, 2011, 8:30am UTC](https://discuss.elastic.co/t/how-do-i-make-an-or-query-with-keywords-using-multiple-fields/4918 "2011-07-21T08:30:52Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pawel\_Krakowiak](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pawel_krakowiak/32/2615_2.png) [@Pawel\_Krakowiak](https://discuss.elastic.co/u/Pawel_Krakowiak)\
**Post date:** [July 21, 2011, 8:30am UTC](https://discuss.elastic.co/t/how-do-i-make-an-or-query-with-keywords-using-multiple-fields/4918/1 "2011-07-21T08:30:52Z")

</div>

I posted this on Stack Overflow as well, so feel free to answer there  
if you like: [http://stackoverflow.com/questions/6764553/how-should-i-query-elastic-search-given-my-mapping-and-using-keywords](http://stackoverflow.com/questions/6764553/how-should-i-query-elastic-search-given-my-mapping-and-using-keywords)

I have a fairly simple mapping, which looks like this (streamlined):

{  
"location" : {  
"properties": {  
"name": { "type": "string", "boost": 2.0, "analyzer":  
"snowball" },  
"description": { "type": "string", "analyzer":  
"snowball" }  
}  
}  
}

I want to find all documents that have a certain keyword in EITHER the  
name or the description field (or both). Basically I'm looking for an  
equivalent of a SQL OR query.

Initially I tried this:

{  
"fields" : ["name", "description"],  
"query" : {  
"terms" : {  
"name" : ["savage"],  
"description" : ["savage"]  
},  
"from" : 0,  
"size" : 500  
}  
}

But it was brought to my attention that such query was not analyzed  
and that is why I was getting no results, so I should instead use the  
text query, but when I do this:

{  
"query" : {  
"bool" : {  
"should" : [  
{"text" : {"name" : "savage"}},  
{"text" : {"description" : "savage"}}  
]  
},  
"from" : 0,  
"size" : 500  
}  
}

I am getting an exception of "No query registered for [text]". What is  
the proper way to pull off this query?

---

<div class="post-metadata">

**Author:** ![Clinton\_Gormley](https://avatars.discourse-cdn.com/v4/letter/c/50afbb/32.png) [@Clinton\_Gormley](https://discuss.elastic.co/u/Clinton_Gormley)\
**Post date:** [July 21, 2011, 9:28am UTC](https://discuss.elastic.co/t/how-do-i-make-an-or-query-with-keywords-using-multiple-fields/4918/2 "2011-07-21T09:28:00Z")

</div>

Hi Pawel

> But it was brought to my attention that such query was not analyzed  
> and that is why I was getting no results, so I should instead use the  
> text query, but when I do this:
> 
> {  
> "query" : {  
> "bool" : {  
> "should" : [  
> {"text" : {"name" : "savage"}},  
> {"text" : {"description" : "savage"}}  
> ]  
> },  
> "from" : 0,  
> "size" : 500  
> }  
> }

Your nesting is incorrect:

{  
"query" : {  
"bool" : {  
"should" : [  
{"text" : {"name" : "savage"}},  
{"text" : {"description" : "savage"}}  
]  
}  
},  
"from" : 0,  
"size" : 500  
}

clint

---

<div class="post-metadata">

**Author:** ![Pawel\_Krakowiak](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pawel_krakowiak/32/2615_2.png) [@Pawel\_Krakowiak](https://discuss.elastic.co/u/Pawel_Krakowiak)\
**Post date:** [July 21, 2011, 1:40pm UTC](https://discuss.elastic.co/t/how-do-i-make-an-or-query-with-keywords-using-multiple-fields/4918/3 "2011-07-21T13:40:41Z")

</div>

It throws the same exception still. I made it even simpler:

{  
"query" : {  
"bool" : {  
"should" : [  
{"text" : {"name" : "savage"}},  
{"text" : {"description" : "savage"}}  
]  
}  
}  
}

but it still does not work. I'm querying with curl (query.json is a  
text file with the above contents):

curl -XGET -d @query.json [http://localhost:9200/myindex/locations/\_search](http://localhost:9200/myindex/locations/_search)

On 21 Lip, 11:28, Clinton Gormley [clin...@iannounce.co.uk](mailto:clin...@iannounce.co.uk) wrote:

> Your nesting is incorrect:
> 
> {  
> "query" : {  
> "bool" : {  
> "should" : [  
> {"text" : {"name" : "savage"}},  
> {"text" : {"description" : "savage"}}  
> ]  
> }  
> },  
> "from" : 0,  
> "size" : 500
> 
> }

---

<div class="post-metadata">

**Author:** ![Clinton\_Gormley](https://avatars.discourse-cdn.com/v4/letter/c/50afbb/32.png) [@Clinton\_Gormley](https://discuss.elastic.co/u/Clinton_Gormley)\
**Post date:** [July 21, 2011, 2:00pm UTC](https://discuss.elastic.co/t/how-do-i-make-an-or-query-with-keywords-using-multiple-fields/4918/4 "2011-07-21T14:00:16Z")

</div>

On Thu, 2011-07-21 at 06:40 -0700, Pawel Krakowiak wrote:

> It throws the same exception still. I made it even simpler:
> 
> {  
> "query" : {  
> "bool" : {  
> "should" : [  
> {"text" : {"name" : "savage"}},  
> {"text" : {"description" : "savage"}}  
> ]  
> }  
> }  
> }
> 
> but it still does not work. I'm querying with curl (query.json is a  
> text file with the above contents):
> 
> curl -XGET -d @query.json [http://localhost:9200/myindex/locations/\_search](http://localhost:9200/myindex/locations/_search)

This works for me. Are you sure it is the same error? Are you sure  
you're doing what you think you're doing?

Just try copying and pasting this:

curl [http://localhost:9200/myindex/locations/\_search?pretty=true](http://localhost:9200/myindex/locations/_search?pretty=true) -d '  
{  
"query" : {  
"bool" : {  
"should" : [  
{"text" : {"name" : "savage"}},  
{"text" : {"description" : "savage"}}  
]  
}  
}  
}  
'

clint

---

<div class="post-metadata">

**Author:** ![Pawel\_Krakowiak](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pawel_krakowiak/32/2615_2.png) [@Pawel\_Krakowiak](https://discuss.elastic.co/u/Pawel_Krakowiak)\
**Post date:** [July 21, 2011, 3:19pm UTC](https://discuss.elastic.co/t/how-do-i-make-an-or-query-with-keywords-using-multiple-fields/4918/5 "2011-07-21T15:19:19Z")

</div>

Well, for once - I am having problems running multiline queries on  
Windows (the command line sucks). That is why I was trying to run them  
from files instead (using the -d @filename option).

Anyway, it seems as if something was awry with my installation. I  
wiped out the whole directory including data and put up a fresh 0.17.1  
and recreated the index with data, then incorporated a text query into  
my application and it started working.

On a side note - how one is supposed to upgrade ES? I thought it was  
simply a matter of overwriting files (of course while ES is down) from  
a new archive?

On 21 Lip, 16:00, Clinton Gormley [clin...@iannounce.co.uk](mailto:clin...@iannounce.co.uk) wrote:

> On Thu, 2011-07-21 at 06:40 -0700, Pawel Krakowiak wrote:
> 
> > It throws the same exception still. I made it even simpler:
> 
> > {  
> > "query" : {  
> > "bool" : {  
> > "should" : [  
> > {"text" : {"name" : "savage"}},  
> > {"text" : {"description" : "savage"}}  
> > ]  
> > }  
> > }  
> > }
> 
> > but it still does not work. I'm querying with curl (query.json is a  
> > text file with the above contents):
> 
> > curl -XGET -d @query.jsonhttp://localhost:9200/myindex/locations/\_search
> 
> This works for me. Are you sure it is the same error? Are you sure  
> you're doing what you think you're doing?
> 
> Just try copying and pasting this:
> 
> curlhttp://localhost:9200/myindex/locations/\_search?pretty=true-d '  
> {  
> "query" : {  
> "bool" : {  
> "should" : [  
> {"text" : {"name" : "savage"}},  
> {"text" : {"description" : "savage"}}  
> ]  
> }  
> }}
> 
> '
> 
> clint

---

<div class="post-metadata">

**Author:** ![Clinton\_Gormley](https://avatars.discourse-cdn.com/v4/letter/c/50afbb/32.png) [@Clinton\_Gormley](https://discuss.elastic.co/u/Clinton_Gormley)\
**Post date:** [July 21, 2011, 3:21pm UTC](https://discuss.elastic.co/t/how-do-i-make-an-or-query-with-keywords-using-multiple-fields/4918/6 "2011-07-21T15:21:50Z")

</div>

On Thu, 2011-07-21 at 08:19 -0700, Pawel Krakowiak wrote:

> Well, for once - I am having problems running multiline queries on  
> Windows (the command line sucks). That is why I was trying to run them  
> from files instead (using the -d @filename option).
> 
> Anyway, it seems as if something was awry with my installation. I  
> wiped out the whole directory including data and put up a fresh 0.17.1  
> and recreated the index with data, then incorporated a text query into  
> my application and it started working.
> 
> On a side note - how one is supposed to upgrade ES? I thought it was  
> simply a matter of overwriting files (of course while ES is down) from  
> a new archive?

It is, but you don't want to leave old libs in there - they can cause  
conflicts

clint

---

<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, 3:59am UTC](https://discuss.elastic.co/t/how-do-i-make-an-or-query-with-keywords-using-multiple-fields/4918/7 "2017-07-06T03:59:53Z")

</div>


