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

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 -

    {
    	"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!

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

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

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