I work with Liferay 7.2 and I need to make an Elasticsearch query that finds als DLFileEntries that have the Document Type "XY". Currently I need to do this in Postman.
I am already able to find all DLFileEntry:
{
"query": {
"bool": {
"must": [
{
"match": {
"entryClassName": "com.liferay.document.library.kernel.model.DLFileEntry"
}
}
]
}
}
}
But I need to find only these DLFileEntry that have Document Type "XY".
How can I do this?
You can simply add another
matchto the fieldfileEntryTypeId, where its value must be equal to the created Document Type id. You can find this id on tabledlfileentrytypeon columnfileentrytypeid. Considering the id equals37105, the query would be like thisedit: Responding to your comment about how to search the
DLFileEntryby itsDLFileEntryTypename, there is no direct way to do this as theDLFileEntryTypeis not indexed on Elastic Search by default. It would also probably need sub queries to achieve this and Elastic Search doesn't support sub queries.With that in mind, the easiest approach I can think of is to customize the way
DLFileEntryis indexed on Elastic Search, adding the fieldfileEntryTypeName. For that, you only need to implement a ModelDocumentContributor forDLFileEntryand add thefileEntryTypeNamefield to the document.Basically, you just need to create a class like this:
As the
DLFileEntryTypename is localized, you should probably index it as a localized value:Now your query will be something like this:
The name fileEntryTypeName_en_US depends on your site default locale. For example, if it is pt_BR, the name would be fileEntryTypeName_pt_BR.
Obs.: The
fileEntryTypename field is not unique, as it is localized, so you might find files with the samefileEntryTypename but differentfileEntryType.