I have list of document ids. When I query Elasticsearch, In result I need document ids which are matching my criteria and documentIds for which documents do not exist in Elasticsearch.
Background on use case
I need to search for missing reports for sites. DocumentId of report is the siteId.
A report is missing if its reportState is NEW (not submitted) or if it doesn't exist in Elasticsearch.
Expected Request and Response
Request: all sites i.e documentIds in request to Elasticsearch
[ABC1, ABC2, ABC3]
Documents in Elasticsearch
[ABC1 with reportState NEW, ABC2 with reportState SUBMITTED, ABC3 document doesn't exist with this documentId]
Now I want to build query X such that my response will retrieve below documentIds.
A query can never return documents that do not exist, so I do not see how you can build a query to return what you describe. If you knew you expected these two documents you could write a query to return the first one and deduce the other one is not present in the client application.
Can you perhaps initially create documents matching all reports you expect and let these have a special field that indicate that they do not yet exist. When you submit a report you overwrite this with the proper document. This way you might be able to adjust your search criteria to return these together with the matching ones.
We have DynamoDB as primary storage, we would require to build a complex mechanism to create documents by default for our use case. That would be last option for us. Looking to solve using Elasticsearch itself.