package alien4cloud.metaproperty;

import com.google.common.collect.Lists;
import org.elasticsearch.mapping.IFacetBuilderHelper;
import org.elasticsearch.mapping.TermsFilterBuilderHelper;
import org.elasticsearch.search.aggregations.AggregationBuilder;
import org.elasticsearch.search.aggregations.AggregationBuilders;
import org.elasticsearch.search.aggregations.bucket.missing.MissingAggregationBuilder;
import org.elasticsearch.search.aggregations.bucket.terms.TermsAggregationBuilder;

import java.util.List;

class MetaPropertyAggregationBuilderHelper extends TermsFilterBuilderHelper implements IFacetBuilderHelper {

    private final int size;

    MetaPropertyAggregationBuilderHelper(String nestedPath,String esFieldName) {
        super(false,nestedPath,esFieldName);

        this.size = 10;
    }

    @Override
    public List<AggregationBuilder> buildFacets() {
        TermsAggregationBuilder termsBuilder = AggregationBuilders.terms(getEsFieldName()).field(getEsFieldName()+".keyword").size(size);
        MissingAggregationBuilder missingBuilder = AggregationBuilders.missing("missing_" + getEsFieldName()).field(getEsFieldName()+".keyword");

        return Lists.newArrayList(termsBuilder, missingBuilder);
    }
}

@@ -68,16 +68,176 @@
 .Lists;%0A
+import org.elasticsearch.index.query.ExistsQueryBuilder;%0Aimport org.elasticsearch.index.query.QueryBuilder;%0Aimport org.elasticsearch.index.query.QueryBuilders;%0A
 import o
@@ -274,32 +274,32 @@
 tBuilderHelper;%0A
-
 import org.elast
@@ -929,16 +929,17 @@
 ieldName
+ 
 );%0A%0A    
@@ -1381,16 +1381,178 @@
 ilder);%0A
-
     %7D%0A
+%0A%0A    @Override%0A    public QueryBuilder buildFilter(final String key, final String... values) %7B%0A        return super.buildFilter(key + %22.keyword%22,values);%0A    %7D%0A%0A
 %7D%0A

Fix for String MetaProps facet searches