Elasticsearch不应该操作查询

时间:2016-02-10 08:08:00

标签: elasticsearch

假设我们可以将pub匹配为

plot

我怎么能暗示一个" shouldNot"对于("name"="A" AND "name!="B")

的操作

BoolQueryBuilder queryBuilder1 = QueryBuilders.boolQuery()
.must(QueryBuilders.matchQuery("name","A"))
.mustNot(QueryBuilders.matchQuery("name","B"));

1 个答案:

答案 0 :(得分:2)

您可以使用:

public class PercentEven {

    public static void main(String args[]){
        int count = 0;
        int[] a={2, 5, 9, 11, 0}; // this can be dynamic.I tried diff values 
        double percent = 0.0;
        if (a.length > 0){
            for ( int i = 0; i < a.length; i++){
                if ( a[i] % 2 == 0){
                    count++;
                }
            }
                percent  = (100*count/a.length);
        }
        System.out.println(percent);
    }
}