# Filter inner hits at display

**URL:** <https://discuss.elastic.co/t/filter-inner-hits-at-display/173539>\
**Category:** Elasticsearch\
**Created:** [March 22, 2019, 5:30pm UTC](https://discuss.elastic.co/t/filter-inner-hits-at-display/173539 "2019-03-22T17:30:35Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![rodrigue](https://avatars.discourse-cdn.com/v4/letter/r/f04885/32.png) [@rodrigue](https://discuss.elastic.co/u/rodrigue)\
**Post date:** [March 22, 2019, 5:30pm UTC](https://discuss.elastic.co/t/filter-inner-hits-at-display/173539/1 "2019-03-22T17:30:36Z")

</div>

Hello, Im' writing to you because I have a problem and I can't find the answer myself.  
I'm indexing documents, with nested paragraphs.  
Ex : {  
"title": "how to recyle"  
"paragraph" : [  
"title": "about iron",  
"warning": "badWords"  
]  
}  
It's just an exemple.

Let's imagine that I want to search for "recycle iron". I would like my document to match, but I don't want the paragraph to show up because it contains "badWords"... Is it possible.  
My problem is that, if I exclude paragraphs with "badWords", the document doesn't match at all.

Here is my query (I know, the query is too big, but it's part of a bigger query)  
This query make sur that both words are present, in the title OR the text.

The best, for me would be to exclude, the uis, but only when I display the result. I still want the document to match. Is it possible? With some kind of post\_filter?

{  
"query": {  
"bool": {  
"must": [  
{  
"bool": {  
"minimum\_should\_match": "2\<80%",  
"should": [  
{  
"bool": {  
"should": [  
{  
"multi\_match": {  
"query": "recycle",  
"fields": [  
"title"  
],  
"type": "phrase",  
"boost": 1  
}  
},  
{  
"nested": {  
"path": "paragraph",  
"query": {  
"bool": {  
"must": [  
{  
"multi\_match": {  
"query": "recycle",  
"fields": [  
"paragraph.text"  
],  
"type": "phrase",  
"boost": 1  
}  
}  
]  
}  
},  
"inner\_hits": {  
"size": 100  
}  
}  
}  
]  
}  
},  
{  
"bool": {  
"should": [  
{  
"multi\_match": {  
"query": "iron",  
"fields": [  
"title"  
],  
"type": "phrase",  
"boost": 1  
}  
},  
{  
"nested": {  
"path": "paragraph",  
"query": {  
"bool": {  
"must": [  
{  
"multi\_match": {  
"query": "iron",  
"fields": [  
"paragraph.text"  
],  
"type": "phrase",  
"boost": 1  
}  
}  
]  
}  
},  
"inner\_hits": {  
"size": 100  
}  
}  
}  
]  
}  
}  
]  
}  
}  
]  
}  
},  
"from": 0,  
"size": 10  
}

---

<div class="post-metadata">

**Author:** ![rodrigue](https://avatars.discourse-cdn.com/v4/letter/r/f04885/32.png) [@rodrigue](https://discuss.elastic.co/u/rodrigue)\
**Post date:** [March 22, 2019, 6:07pm UTC](https://discuss.elastic.co/t/filter-inner-hits-at-display/173539/2 "2019-03-22T18:07:04Z")

</div>

Hello,  
Finally I found the solution. If I add, at the end of the query, a "should" -\> "nested" -\> "query" -\> "filter", I can make a separate query that has no impact on the score (it's a should containing a filter). If I repeat my query ("recycle iron") and add the badWords query, it filters my inner\_hits.  
Gosh, my query gets bigger and bigger

---

<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:** [April 19, 2019, 6:07pm UTC](https://discuss.elastic.co/t/filter-inner-hits-at-display/173539/3 "2019-04-19T18:07:06Z")

</div>

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