I also had this problem. I fixed it by filtering on the 'documentpublishto' field.
You need to make this field filterable first.
[assembly: RegisterModule(typeof(CustomAzureSearchModule))]
namespace Core.Modules
{
public class CustomAzureSearchModule : Module
{
public CustomAzureSearchModule()
: base(nameof(CustomAzureSearchModule))
{
}
protected override void OnInit()
{
base.OnInit();
DocumentFieldCreator.Instance.CreatingField.After += CreatingField_After;
}
private void CreatingField_After(object sender, CreateFieldEventArgs e)
{
var field = e.Field;
if (field.Name.Equals(nameof(TreeNode.DocumentPublishTo), StringComparison.OrdinalIgnoreCase))
{
field.IsFilterable = true;
}
}
}
}
Then you can use the following query to check if the page is published.
$"documentpublishto eq null or documentpublishto gt {DateTimeOffset.UtcNow.ToString("O", CultureInfo.InvariantCulture)}"