How to make a nested query to filter when searching by a ddmFieldArray elem

Olaf Kock, modified 1 Year ago. New Member Posts: 3 Join Date: 2/3/22 Recent Posts

Hi!

I want to make a boolean query that gets the value of a field of a structure called "isFinal" that has "YES" and "NO" as values, and filter the Journal Articles according to this.

I had the following code for achieving that, but I am not introducing the value "YES" (which is the one I want to filter) anywhere, how can I make it?

//This is the principal query
BooleanQuery booleanQuery = queries.booleanQuery();

//Here starts the code for the nested one
BooleanQuery boolQueryForNested = queries.booleanQuery();
TermQuery termQuery = queries.term("ddmFieldArray.ddmFieldName", "ddm__keyword__" + prestacionStructure.getStructureId() + "__isFinal_es_ES");
boolQueryForNested.addFilterQueryClauses(termQuery);
NestedQuery nestedQuery = queries.nested("ddmFieldArray", boolQueryForNested);
booleanQuery.addMustNotQueryClauses(nestedQuery);

Thank you in advance! 

thumbnail
Jamie Sammons, modified 9 Months ago. New Member Posts: 3 Join Date: 12/6/24 Recent Posts

Hello Maria Z,

The solution is to use a BooleanQuery with TermQuery to search for specific values within these nested fields. For example, you can target fields like ddmFieldArray.ddmFieldName and ddmFieldArray.ddmFieldValueKeyword_en_US

To know more: https://www.surekhatech.com/blog/create-a-nested-query-to-filter-searches-by-ddmfieldarray-element-in-liferay