@@ -223,18 +223,10 @@ private void processFilterAnnotation(List<IFilterBuilderHelper> classFilters, St
223223 }
224224 for (String path : paths ) {
225225 path = path .trim ();
226- boolean isAnalyzed = isAnalyzed (indexable );
227- String nestedPath = indexable .getAnnotation (NestedObject .class ) == null ? null : esFieldName ;
228- if (nestedPath == null ) {
229- int nestedIndicator = esFieldName .lastIndexOf ("." );
230- if (nestedIndicator > 0 ) {
231- nestedPath = esFieldName .substring (0 , nestedIndicator );
232- esFieldName = esFieldName .substring (nestedIndicator + 1 , esFieldName .length ());
233- }
226+ addFilter (classFilters , esFieldName , indexable , path , isAnalyzed (indexable , null ));
227+ for (String alternateFieldName : alternateFieldNames (indexable )) {
228+ addFilter (classFilters , alternateFieldName , indexable , path , isAnalyzed (indexable , alternateFieldName ));
234229 }
235- String filterPath = getFilterPath (path , esFieldName );
236-
237- classFilters .add (new TermsFilterBuilderHelper (isAnalyzed , nestedPath , filterPath ));
238230 }
239231 return ;
240232 }
@@ -245,6 +237,20 @@ private void processFilterAnnotation(List<IFilterBuilderHelper> classFilters, St
245237 }
246238 }
247239
240+ private void addFilter (List <IFilterBuilderHelper > classFilters , String esFieldName , Indexable indexable , String path , boolean isAnalyzed ) {
241+ String nestedPath = indexable .getAnnotation (NestedObject .class ) == null ? null : esFieldName ;
242+ if (nestedPath == null ) {
243+ int nestedIndicator = esFieldName .lastIndexOf ("." );
244+ if (nestedIndicator > 0 ) {
245+ nestedPath = esFieldName .substring (0 , nestedIndicator );
246+ esFieldName = esFieldName .substring (nestedIndicator + 1 , esFieldName .length ());
247+ }
248+ }
249+ String filterPath = getFilterPath (path , esFieldName );
250+
251+ classFilters .add (new TermsFilterBuilderHelper (isAnalyzed , nestedPath , filterPath ));
252+ }
253+
248254 private void processFacetAnnotation (List <IFacetBuilderHelper > classFacets , List <IFilterBuilderHelper > classFilters , String esFieldName ,
249255 Indexable indexable ) {
250256 TermsFacet termsFacet = indexable .getAnnotation (TermsFacet .class );
@@ -263,17 +269,11 @@ private void processFacetAnnotation(List<IFacetBuilderHelper> classFacets, List<
263269 }
264270 for (String path : paths ) {
265271 path = path .trim ();
266- boolean isAnalyzed = isAnalyzed (indexable );
267- String nestedPath = indexable .getAnnotation (NestedObject .class ) == null ? null : esFieldName ;
268- String filterPath = getFilterPath (path , esFieldName );
269-
270- IFacetBuilderHelper facetBuilderHelper = new TermsAggregationBuilderHelper (isAnalyzed , nestedPath , filterPath , termsFacet );
271- classFacets .add (facetBuilderHelper );
272- if (classFilters .contains (facetBuilderHelper )) {
273- classFilters .remove (facetBuilderHelper );
274- LOGGER .warn ("Field <" + esFieldName + "> already had a filter that will be replaced by the defined facet. Only a single one is allowed." );
272+
273+ addAggregation (termsFacet , indexable , esFieldName , path , isAnalyzed (indexable , null ), classFacets , classFilters );
274+ for (String alternateFieldName : alternateFieldNames (indexable )) {
275+ addAggregation (termsFacet , indexable , alternateFieldName , path , isAnalyzed (indexable , alternateFieldName ), classFacets , classFilters );
275276 }
276- classFilters .add (facetBuilderHelper );
277277 }
278278 return ;
279279 }
@@ -293,15 +293,50 @@ private String getFilterPath(String path, String esFieldName) {
293293 return path .isEmpty () ? esFieldName : esFieldName + "." + path ;
294294 }
295295
296- private boolean isAnalyzed (Indexable indexable ) {
296+ private boolean isAnalyzed (Indexable indexable , String name ) {
297297 boolean isAnalysed = true ;
298+ StringFieldMulti multiAnnotation = indexable .getAnnotation (StringFieldMulti .class );
299+ if (multiAnnotation != null ) {
300+ if (name == null ) {
301+ return IndexType .analyzed .equals (multiAnnotation .main ().indexType ());
302+ } else {
303+ for (int i = 0 ; i < multiAnnotation .multiNames ().length ; i ++) {
304+ if (multiAnnotation .multiNames ()[i ].equals (name )) {
305+ return IndexType .analyzed .equals (multiAnnotation .multi ()[i ].indexType ());
306+ }
307+ }
308+ }
309+ }
310+
298311 StringField stringFieldAnnotation = indexable .getAnnotation (StringField .class );
299- if (stringFieldAnnotation != null && ! IndexType . analyzed . equals ( stringFieldAnnotation . indexType ()) ) {
300- isAnalysed = false ;
312+ if (stringFieldAnnotation != null ) {
313+ return IndexType . analyzed . equals ( stringFieldAnnotation . indexType ()) ;
301314 }
302315 return isAnalysed ;
303316 }
304317
318+ private void addAggregation (TermsFacet termsFacet , Indexable indexable , String esFieldName , String path , boolean isAnalyzed ,
319+ List <IFacetBuilderHelper > classFacets , List <IFilterBuilderHelper > classFilters ) {
320+ String nestedPath = indexable .getAnnotation (NestedObject .class ) == null ? null : esFieldName ;
321+ String filterPath = getFilterPath (path , esFieldName );
322+
323+ IFacetBuilderHelper facetBuilderHelper = new TermsAggregationBuilderHelper (isAnalyzed , nestedPath , filterPath , termsFacet );
324+ classFacets .add (facetBuilderHelper );
325+ if (classFilters .contains (facetBuilderHelper )) {
326+ classFilters .remove (facetBuilderHelper );
327+ LOGGER .warn ("Field <" + esFieldName + "> already had a filter that will be replaced by the defined facet. Only a single one is allowed." );
328+ }
329+ classFilters .add (facetBuilderHelper );
330+ }
331+
332+ private String [] alternateFieldNames (Indexable indexable ) {
333+ StringFieldMulti multi = indexable .getAnnotation (StringFieldMulti .class );
334+ if (multi == null ) {
335+ return new String [0 ];
336+ }
337+ return multi .multiNames ();
338+ }
339+
305340 private void processStringOrPrimitive (Class <?> clazz , Map <String , Object > propertiesDefinitionMap , String pathPrefix , Indexable indexable ) {
306341 processFieldAnnotation (IndexName .class , new IndexNameAnnotationParser (), propertiesDefinitionMap , pathPrefix , indexable );
307342 processFieldAnnotation (NullValue .class , new NullValueAnnotationParser (), propertiesDefinitionMap , pathPrefix , indexable );
0 commit comments