# Complexe query ( for me ;) ) with many match\_all and range

**URL:** <https://discuss.elastic.co/t/complexe-query-for-me-with-many-match-all-and-range/19548>\
**Category:** Elasticsearch\
**Created:** [September 1, 2014, 9:56am UTC](https://discuss.elastic.co/t/complexe-query-for-me-with-many-match-all-and-range/19548 "2014-09-01T09:56:42Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![alain\_ibrahim](https://avatars.discourse-cdn.com/v4/letter/a/ebca7d/32.png) [@alain\_ibrahim](https://discuss.elastic.co/u/alain_ibrahim)\
**Post date:** [September 1, 2014, 9:56am UTC](https://discuss.elastic.co/t/complexe-query-for-me-with-many-match-all-and-range/19548/1 "2014-09-01T09:56:42Z")

</div>

Hello

I'm quite new on elasticsearch.

I made a form who query an elasticsearch document for getting the datas.

In the form there is mutiple input :  
image\_yes : checkbox  
NAME : string  
COLLECTION : string  
CATALOGNUMBER:string  
RECORDNUMBER: string  
LOCALISATION: string  
EVENTID : integer  
event\_date\_start: year integer  
event\_date\_end: year integer

the search is general: on all the fields of the document  
I made many simples queries who works but i can't make a complexe one  
working with AND and RANGE. All the exemples i see use "match\_all:{}".  
I also need the use of "\*" and "?" in the query.

_this work ok:_

curl -XGET 'localhost:9200/donnees/specimens/\_search?pretty=true' -d '{  
"fields" : ["EVENTID", "CATALOGNUMBER", "RECORDNUMBER"],  
"query" : {  
"query\_string" : {  
"query" : "CATALOGNUMBER:P000023\*"

```
    }         
}

```

}'

curl -XGET 'localhost:9200/donnees/specimens/\_search?pretty=true' -d '{  
"fields" : ["EVENTID", "CATALOGNUMBER", "RECORDNUMBER"],  
"query" : {  
"filtered" : {  
"filter" : {  
"range":{"EVENTID": {"from" : 36,  
"to" : 50,  
"include\_lower" : true,  
"include\_upper" : false}  
}  
}  
}  
}  
}'

_this working ok too:_

curl -XGET 'localhost:9200/donnees/specimens/\_search?pretty=true' -d '{  
"fields" : ["EVENTID", "CATALOGNUMBER", "RECORDNUMBER"],  
"query" : {  
"bool" : {  
"must" : [  
{  
"query\_string":{"query" : "CATALOGNUMBER:P000023\*"}  
},  
{  
"query\_string":{"query" :  
"RECORDNUMBER:recordnumber236\*"}  
}  
]  
}  
},  
"highlight": {"pre\_tags": ["**"], "post\_tags": ["**"],  
"fields": {"\*": {}}},  
"facets": {  
"lifestage": {"terms": { "field": "LIFESTAGE", "size": 20}},  
"sex": {"terms": {"field": "SEX", "size": 20}},  
"continent": {"terms": {"field": "CONTINENT", "size": 20}},  
"institutioncode": {"terms": {"field": "INSTITUTIONCODE", "size":  
20 }}  
}  
}'

\*trying to merge but fail : \*  
I need that the facets are made with the results so i can't use "filtering"  
if i understand good.  
I try many syntaxes but nothink good.

(error)  
curl -XGET 'localhost:9200/donnees/specimens/\_search?pretty=true' -d '{  
"fields" : ["EVENTID", "CATALOGNUMBER", "RECORDNUMBER"],  
"query" : {  
"filtered" : {  
"filter" : {  
"range":{"EVENTID": {"from" : 36,  
"to" : 50,  
"include\_lower" : true,  
"include\_upper" : false}  
}  
},  
"query\_string" : {  
"query" : "CATALOGNUMBER:P000023\*"  
}  
}  
},  
"highlight": {"pre\_tags": ["**"], "post\_tags": ["**"],  
"fields": {"_": {}}},  
"facets": {  
"lifestage": {"terms": { "field": "LIFESTAGE", "size": 20}},  
"sex": {"terms": {"field": "SEX", "size": 20}},  
"continent": {"terms": {"field": "CONTINENT", "size": 20}},  
"institutioncode": {"terms": {"field": "INSTITUTIONCODE", "size":  
20 }}  
}  
}'  
error :  
curl -XGET 'localhost:9200/donnees/specimens/\_search?pretty=true' -d '{  
"fields" : ["EVENTID", "CATALOGNUMBER", "RECORDNUMBER"],  
"query" : {  
"filtered" : {  
"filter" : {  
"range":{"EVENTID": {"from" : 36,  
"to" : 50,  
"include\_lower" : true,  
"include\_upper" : false}  
}  
}  
},  
"query\_string" : { "query" : "CATALOGNUMBER:P000023_" }  
},  
"highlight": {"pre\_tags": ["**"], "post\_tags": ["**"],  
"fields": {"\*": {}}},  
"facets": {  
"lifestage": {"terms": { "field": "LIFESTAGE", "size": 20}},  
"sex": {"terms": {"field": "SEX", "size": 20}},  
"continent": {"terms": {"field": "CONTINENT", "size": 20}},  
"institutioncode": {"terms": {"field": "INSTITUTIONCODE", "size":  
20 }}  
}  
}'

how can i put a AND query with Range please ?

I whish somethink like this in pseudo sql:

select \* from document where :  
image\_yes is true  
AND NAME : "name"  
AND COLLECTION : "collection\*"  
AND CATALOGNUMBER:"catalognumber\*"  
AND RECORDNUMBER:"recordnumber\*"  
AND LOCALISATION: "localisation"  
AND  
"range":{"EVENTID": {"from" : 36, "include\_lower" : true  
}  
AND  
"range":{" event\_date": {"from" : event\_date\_start,  
"to" : event\_data\_end,  
"include\_lower" : true,  
"include\_upper" : false}  
}

Many thanks  
Alain

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/2d8f34dd-37bf-4850-8bc3-cd4b84ac02db%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/2d8f34dd-37bf-4850-8bc3-cd4b84ac02db%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![alain\_ibrahim](https://avatars.discourse-cdn.com/v4/letter/a/ebca7d/32.png) [@alain\_ibrahim](https://discuss.elastic.co/u/alain_ibrahim)\
**Post date:** [September 1, 2014, 11:20am UTC](https://discuss.elastic.co/t/complexe-query-for-me-with-many-match-all-and-range/19548/2 "2014-09-01T11:20:12Z")

</div>

EDIT 1 ;

this seem to work for begining :

curl -XGET 'localhost:9200/donnees/specimens/\_search?pretty=true' -d '{  
"fields" : ["E\_EVENTID", "O\_CATALOGNUMBER", "O\_RECORDNUMBER"],  
"query" : {  
"bool" : {  
"must" : [  
{  
"query\_string":{"query" : "O\_CATALOGNUMBER:P000023\*"}  
},  
{  
"query\_string":{"query" :  
"O\_RECORDNUMBER:recordnumber236\*"}  
},  
{  
"range" : {  
"E\_EVENTID" : {  
"gte" : 36,  
"lte" : 60  
}  
}  
}  
]  
}  
},  
"highlight": {"pre\_tags": ["**"], "post\_tags": ["**"],  
"fields": {"\*": {}}},  
"facets": {  
"lifestage": {"terms": { "field": "O\_LIFESTAGE", "size": 20}},  
"sex": {"terms": {"field": "O\_SEX", "size": 20}},  
"continent": {"terms": {"field": "L\_CONTINENT", "size": 20}},  
"institutioncode": {"terms": {"field": "I\_INSTITUTIONCODE", "size":  
20 }}  
}  
}'

Le lundi 1 septembre 2014 11:56:42 UTC+2, alain ibrahim a écrit :

> Hello
> 
> I'm quite new on elasticsearch.
> 
> I made a form who query an elasticsearch document for getting the datas.
> 
> In the form there is mutiple input :  
> image\_yes : checkbox  
> NAME : string  
> COLLECTION : string  
> CATALOGNUMBER:string  
> RECORDNUMBER: string  
> LOCALISATION: string  
> EVENTID : integer  
> event\_date\_start: year integer  
> event\_date\_end: year integer
> 
> the search is general: on all the fields of the document  
> I made many simples queries who works but i can't make a complexe one  
> working with AND and RANGE. All the exemples i see use "match\_all:{}".  
> I also need the use of "\*" and "?" in the query.
> 
> _this work ok:_
> 
> curl -XGET 'localhost:9200/donnees/specimens/\_search?pretty=true' -d '{  
> "fields" : ["EVENTID", "CATALOGNUMBER", "RECORDNUMBER"],  
> "query" : {  
> "query\_string" : {  
> "query" : "CATALOGNUMBER:P000023\*"
> 
> ```
> }         
> }
> 
> ```
> 
> }'
> 
> curl -XGET 'localhost:9200/donnees/specimens/\_search?pretty=true' -d '{  
> "fields" : ["EVENTID", "CATALOGNUMBER", "RECORDNUMBER"],  
> "query" : {  
> "filtered" : {  
> "filter" : {  
> "range":{"EVENTID": {"from" : 36,  
> "to" : 50,  
> "include\_lower" : true,  
> "include\_upper" : false}  
> }  
> }  
> }  
> }  
> }'
> 
> _this working ok too:_
> 
> curl -XGET 'localhost:9200/donnees/specimens/\_search?pretty=true' -d '{  
> "fields" : ["EVENTID", "CATALOGNUMBER", "RECORDNUMBER"],  
> "query" : {  
> "bool" : {  
> "must" : [  
> {  
> "query\_string":{"query" : "CATALOGNUMBER:P000023\*"}  
> },  
> {  
> "query\_string":{"query" :  
> "RECORDNUMBER:recordnumber236\*"}  
> }  
> ]  
> }  
> },  
> "highlight": {"pre\_tags": ["**"], "post\_tags": ["**"],  
> "fields": {"\*": {}}},  
> "facets": {  
> "lifestage": {"terms": { "field": "LIFESTAGE", "size": 20}},  
> "sex": {"terms": {"field": "SEX", "size": 20}},  
> "continent": {"terms": {"field": "CONTINENT", "size": 20}},  
> "institutioncode": {"terms": {"field": "INSTITUTIONCODE", "size":  
> 20 }}  
> }  
> }'
> 
> \*trying to merge but fail : \*  
> I need that the facets are made with the results so i can't use  
> "filtering" if i understand good.  
> I try many syntaxes but nothink good.
> 
> (error)  
> curl -XGET 'localhost:9200/donnees/specimens/\_search?pretty=true' -d '{  
> "fields" : ["EVENTID", "CATALOGNUMBER", "RECORDNUMBER"],  
> "query" : {  
> "filtered" : {  
> "filter" : {  
> "range":{"EVENTID": {"from" : 36,  
> "to" : 50,  
> "include\_lower" : true,  
> "include\_upper" : false}  
> }  
> },  
> "query\_string" : {  
> "query" : "CATALOGNUMBER:P000023\*"  
> }  
> }  
> },  
> "highlight": {"pre\_tags": ["**"], "post\_tags": ["**"],  
> "fields": {"_": {}}},  
> "facets": {  
> "lifestage": {"terms": { "field": "LIFESTAGE", "size": 20}},  
> "sex": {"terms": {"field": "SEX", "size": 20}},  
> "continent": {"terms": {"field": "CONTINENT", "size": 20}},  
> "institutioncode": {"terms": {"field": "INSTITUTIONCODE", "size":  
> 20 }}  
> }  
> }'  
> error :  
> curl -XGET 'localhost:9200/donnees/specimens/\_search?pretty=true' -d '{  
> "fields" : ["EVENTID", "CATALOGNUMBER", "RECORDNUMBER"],  
> "query" : {  
> "filtered" : {  
> "filter" : {  
> "range":{"EVENTID": {"from" : 36,  
> "to" : 50,  
> "include\_lower" : true,  
> "include\_upper" : false}  
> }  
> }  
> },  
> "query\_string" : { "query" : "CATALOGNUMBER:P000023_" }  
> },  
> "highlight": {"pre\_tags": ["**"], "post\_tags": ["**"],  
> "fields": {"\*": {}}},  
> "facets": {  
> "lifestage": {"terms": { "field": "LIFESTAGE", "size": 20}},  
> "sex": {"terms": {"field": "SEX", "size": 20}},  
> "continent": {"terms": {"field": "CONTINENT", "size": 20}},  
> "institutioncode": {"terms": {"field": "INSTITUTIONCODE", "size":  
> 20 }}  
> }  
> }'
> 
> how can i put a AND query with Range please ?
> 
> I whish somethink like this in pseudo sql:
> 
> select \* from document where :  
> image\_yes is true  
> AND NAME : "name"  
> AND COLLECTION : "collection\*"  
> AND CATALOGNUMBER:"catalognumber\*"  
> AND RECORDNUMBER:"recordnumber\*"  
> AND LOCALISATION: "localisation"  
> AND  
> "range":{"EVENTID": {"from" : 36, "include\_lower" : true  
> }  
> AND  
> "range":{" event\_date": {"from" : event\_date\_start,  
> "to" : event\_data\_end,  
> "include\_lower" : true,  
> "include\_upper" : false}  
> }
> 
> Many thanks  
> Alain

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/cb885e1e-8db5-4001-abf9-e24fc7839913%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/cb885e1e-8db5-4001-abf9-e24fc7839913%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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:05am UTC](https://discuss.elastic.co/t/complexe-query-for-me-with-many-match-all-and-range/19548/3 "2017-07-06T01:05:10Z")

</div>

Closed on July 6, 2017, 1:05am UTC


