# Full text search all Indexes but filter out blog posts that aren't published

**URL:** <https://discuss.elastic.co/t/full-text-search-all-indexes-but-filter-out-blog-posts-that-arent-published/240557>\
**Category:** Elasticsearch\
**Created:** [July 9, 2020, 3:46pm UTC](https://discuss.elastic.co/t/full-text-search-all-indexes-but-filter-out-blog-posts-that-arent-published/240557 "2020-07-09T15:46:32Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Revekius](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/revekius/32/26783_2.png) [@Revekius](https://discuss.elastic.co/u/Revekius)\
**Post date:** [July 9, 2020, 3:46pm UTC](https://discuss.elastic.co/t/full-text-search-all-indexes-but-filter-out-blog-posts-that-arent-published/240557/1 "2020-07-09T15:46:32Z")

</div>

Hi,

I would like to do the following in Elasticsearch 7.8.

1. Do a full text search with fuzzy searching enabled on all indexes
2. Do a secondary search for a specific term on all indexes
3. Filter out on the publishedDate for blog posts (The business logic is that a user can create a blog post and publish it on a certain day. I do not want to show blog posts that are set for the future in my search results.)

I would like to get all of the results from 1&2, and filter them out with 3 if possible.

This is my current query -

```json
    {
    	"query": {
    		"bool": {
    			"should": [
    				{
    					"multi_match": {
    						"fields": [
    							"_all"
    						],
    						"fuzziness": "AUTO",
    						"prefix_length": 2,
    						"query": "Testing"
    					}
    				},
    				{
    					"multi_match": {
    						"query": "Testing"
    					}
    				},
    				{
    					"bool": {
    						"_name": "Filter out blog posts",
    						"must": [
    							{
    								"term": {
    									"_index": "blog"
    								}
    							},
    							{
    								"range": {
    									"blog.publishedDate": {
    										"lte": "now"
    									}
    								}
    							}
    						]
    					}
    				}
    			]
    		}
    	}
    }

```

Thanks for any input!

---

<div class="post-metadata">

**Author:** ![Revekius](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/revekius/32/26783_2.png) [@Revekius](https://discuss.elastic.co/u/Revekius)\
**Post date:** [July 13, 2020, 1:53pm UTC](https://discuss.elastic.co/t/full-text-search-all-indexes-but-filter-out-blog-posts-that-arent-published/240557/2 "2020-07-13T13:53:14Z")

</div>

I updated my query to the following, but I am still unsure of how to restrict the field to a certain index.

```json
{
    "query": {
        "bool": {
            "must_not": [
                {
                    "range": {
                        "publishDate": {
                            "gte": "now"
                        }
                    }
                }
            ],
            "should": [
                {
                    "multi_match": {
                        "fields": [
                            "_all"
                        ],
                        "fuzziness": "AUTO",
                        "prefix_length": 2,
                        "query": "test"
                    }
                },
                {
                    "multi_match": {
                        "query": "test"
                    }
                }
            ]
        }
    }
}

```

---

<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:** [August 10, 2020, 1:53pm UTC](https://discuss.elastic.co/t/full-text-search-all-indexes-but-filter-out-blog-posts-that-arent-published/240557/3 "2020-08-10T13:53:28Z")

</div>

Closed on August 10, 2020, 1:53pm UTC

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