/**
* @author ishaikh
*
*/
package com.transformuk.bdt.util;
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
import static org.elasticsearch.index.query.QueryBuilders.boolQuery;
import static org.elasticsearch.index.query.QueryBuilders.boostingQuery;
import static org.elasticsearch.index.query.QueryBuilders.matchPhraseQuery;
import static org.elasticsearch.index.query.QueryBuilders.matchQuery;
import static org.elasticsearch.index.query.QueryBuilders.multiMatchQuery;
import static org.elasticsearch.index.query.QueryBuilders.queryString;
import java.io.IOException;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.index.query.MatchQueryBuilder.Operator;
import org.elasticsearch.index.query.MultiMatchQueryBuilder.Type;
public class BfSfQueryTemplate {
public static String buildTemplate() throws IOException {
XContentBuilder builder = jsonBuilder()
.startObject()
.field("query",
boolQuery()
.should(multiMatchQuery("categories", "title", "short_description").boost(3))
.should(multiMatchQuery("council", "title", "short_description").boost(0.3f))
.should(boostingQuery()
.positive(queryString("my +ve query")
.boost(0.6f))
.negative(queryString("my -ve query"))
.negativeBoost(-2))
.must(matchQuery("stages", "STAGE"))
.must(multiMatchQuery("region", "locations", "areas").type(Type.BEST_FIELDS).operator(Operator.AND))
.mustNot(matchPhraseQuery("title", "Access to Work"))
)
.endObject().startArray("fields").field("short_description").field("title").endArray();
builder.string();
return builder.toString();
}
}