# Query, but only in records having a specific category

**URL:** https://discuss.elastic.co/t/query-but-only-in-records-having-a-specific-category/20526
**Category:** Elasticsearch
**Created:** [November 1, 2014, 2:22pm UTC](https://discuss.elastic.co/t/query-but-only-in-records-having-a-specific-category/20526 "2014-11-01T14:22:03Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Michael\_Hnat](https://avatars.discourse-cdn.com/v4/letter/m/dbc845/32.png) [@Michael\_Hnat](https://discuss.elastic.co/u/Michael_Hnat)
#### Post date: [November 1, 2014, 2:22pm UTC](https://discuss.elastic.co/t/query-but-only-in-records-having-a-specific-category/20526/1 "2014-11-01T14:22:03Z")

</div>

Hi,

I'm new to elasticsearch, but already very impressed.

But actually I stuck with the following problem:  
This is part of my mapping:

```
"mappings" : {
  "content" : {
    "properties" : {
      "contentid" : { "type" : "string", "index" : "not_analyzed", 

```

"store" : "yes" },  
"title" : { "type" : "string", "boost" : "3", "store" : "yes" },  
"categoryids" : {  
"type" : "multi\_field",  
"fields" : {  
"categoryids" : { "type" : "string", "index" :  
"not\_analyzed", "store" : "yes" },  
"facet" : { "type" : "string", "index" : "not\_analyzed" }  
}  
},  
"summary" : { "type" : "string", "boost" : "3", "store" : "yes",  
"index" : "analyzed", "analyzer" : "german" },  
"body" : { "type" : "string", "index" : "analyzed", "analyzer" :  
"german", "store" : "yes" },  
"searchexclude" : { "type" : "byte", "store" : "yes",  
"null\_value" : "0" },  
....

What I need is a fulltext search over several fields of my records (title,  
summary, body, etc.).  
This is my actual query that works fine:  
GET \_search  
{  
"query": {  
"query\_string": {  
"query": "mySearchTerm"  
}  
}  
,"highlight" : {  
"fields" : {  
"body" : {}  
}  
}  
,"sort" : [  
"\_score",  
{ "jahr" : {"order" : "desc"}}  
]  
,"fields" : ["summary","title","filename","categoryid"]  
};

But now I want only records searched where searchexlude=0 and a specific  
categoryid.

That's the point, where I stuck.  
How can I do a fulltextsearch but only on specifix records?  
What I read in the documentation is, that I need a filtered query, but I  
always get bad requests. Also I read, that filtering means loosing the  
score.

Any help apreciated.

Thanks,  
Michi

--  
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/75eb4771-3979-4ad8-9a29-563ae7f5c4af%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/75eb4771-3979-4ad8-9a29-563ae7f5c4af%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

### Author: ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)
#### Post date: [November 1, 2014, 2:34pm UTC](https://discuss.elastic.co/t/query-but-only-in-records-having-a-specific-category/20526/2 "2014-11-01T14:34:37Z")

</div>

Filtered query is the way to go.  
Filters don't participate to the score does not mean that the query score is reset.

Have a look at [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/help) to see how to send a full example to this list.

HTH

--  
David 😉  
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

> Le 1 nov. 2014 à 15:22, Michael Hnat [mhnat74@googlemail.com](mailto:mhnat74@googlemail.com) a écrit :
> 
> Hi,
> 
> I'm new to elasticsearch, but already very impressed.
> 
> But actually I stuck with the following problem:  
> This is part of my mapping:
> 
> ```
> "mappings" : {
> "content" : {
> "properties" : {
> "contentid" : { "type" : "string", "index" : "not_analyzed", "store" : "yes" },
> "title" : { "type" : "string", "boost" : "3", "store" : "yes" },
> "categoryids" : {
> "type" : "multi_field",
> "fields" : {
> "categoryids" : { "type" : "string", "index" : "not_analyzed", "store" : "yes" },
> "facet" : { "type" : "string", "index" : "not_analyzed" }
> }
> },
> "summary" : { "type" : "string", "boost" : "3", "store" : "yes", "index" : "analyzed", "analyzer" : "german" },
> "body" : { "type" : "string", "index" : "analyzed", "analyzer" : "german", "store" : "yes" },
> "searchexclude" : { "type" : "byte", "store" : "yes", "null_value" : "0" },
> 
> ```
> 
> ....
> 
> What I need is a fulltext search over several fields of my records (title, summary, body, etc.).  
> This is my actual query that works fine:  
> GET \_search  
> {  
> "query": {  
> "query\_string": {  
> "query": "mySearchTerm"  
> }  
> }  
> ,"highlight" : {  
> "fields" : {  
> "body" : {}  
> }  
> }  
> ,"sort" : [  
> "\_score",  
> { "jahr" : {"order" : "desc"}}  
> ]  
> ,"fields" : ["summary","title","filename","categoryid"]  
> };
> 
> But now I want only records searched where searchexlude=0 and a specific categoryid.
> 
> That's the point, where I stuck.  
> How can I do a fulltextsearch but only on specifix records?  
> What I read in the documentation is, that I need a filtered query, but I always get bad requests. Also I read, that filtering means loosing the score.
> 
> Any help apreciated.
> 
> Thanks,  
> Michi
> 
> --  
> 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/75eb4771-3979-4ad8-9a29-563ae7f5c4af%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/75eb4771-3979-4ad8-9a29-563ae7f5c4af%40googlegroups.com).  
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
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/04257577-AC26-48F4-8849-4213E5B9B1F6%40pilato.fr](https://groups.google.com/d/msgid/elasticsearch/04257577-AC26-48F4-8849-4213E5B9B1F6%40pilato.fr).  
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, 12:52am UTC](https://discuss.elastic.co/t/query-but-only-in-records-having-a-specific-category/20526/3 "2017-07-06T00:52:41Z")

</div>


