I'm confused as to when the query_string query with custom sort order is executed in a query vs filter context. I listed two queries, query 1 deliberately not specifying the filter context and query 2 with the bool/filter expression to "activate" the filter context, both with custom sort orders.
From an ElasticSearch/Lucene point of view, are both queries the same? And do both queries yield the same performance?
Query 1
curl -XGET 'localhost:9200/my-index/_search?pretty' -d'
{
"query": {
"query_string": {
"query": "title:Tesla"
}
},
"sort": { "publishedAt": { "order": "desc" } }
}`
Query 2
curl -XGET 'localhost:9200/my-index/_search?pretty' -d'
{
"query": {
"bool": {
"filter": {
"query_string": {
"query": "title:Tesla"
}
}
}
},
"sort": { "publishedAt": { "order": "desc" } }
}'
Background Info
For my use case, ElasticSearch document scoring is not required. All good with scoring disabled by the custom sort order. I also want to ensure that queries are run in a filter context to ensure shard-based caching for better search performance. At the moment, I'm using query 1, but I'm uncertain as to whether query 1 actually runs in a filter context.