I am using
QueryBuilder qb = null;
FilterBuilder fb = null;
fb = FilterBuilders.andFilter(
FilterBuilders.termsFilter("dbname", searchDBs))
qb = (QueryBuilder) QueryBuilders.queryString("""+ searchText+ """).field("titlefield");
FilteredQueryBuilder builder = QueryBuilders.filteredQuery(qb,fb);
FunctionScoreQueryBuilder functionbuilder = new FunctionScoreQueryBuilder(builder).add(FilterBuilders.termsFilter("dbname", "test"), factorFunction(-30.0f))
.add(FilterBuilders.rangeFilter("pubdate").gte("2014-01"), factorFunction(10));
srb.setQuery(functionbuilder);
These don't work in elasticsearch 2.0.
Can I get some examples as to how to make these work in 2.0 please?
dadoonet
(David Pilato)
November 17, 2015, 6:08pm
2
I updated the search query to the following. Each time i call setQuery it over writes the previous one. How do I rewrite this query?
QueryBuilder qb = null;
SearchRequestBuilder srb = null;
srb = client.prepareSearch("alias1");
srb = srb.setTypes("site");
qb = (QueryBuilder) QueryBuilders.queryString("""+ searchText+ """).field("titlefield");
srb.setQuery((org.elasticsearch.index.query.QueryBuilder) qb);
//for filtering
BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
boolQueryBuilder.must(QueryBuilders.matchQuery("dbname", searchDBs));
boolQueryBuilder.must(QueryBuilders.rangeQuery("pubdate").from("1890-09").to("2016-08"));
QueryBuilder aScore = QueryBuilders.functionScoreQuery().
add(
QueryBuilders.matchQuery("dbname", "test"),
ScoreFunctionBuilders.weightFactorFunction(10)
);
srb.setQuery(aScore)
How to write the following filtered query using elasticsearch java api?
{
"query": {
"bool": {
"must": [
{ "match": { "title": "Search" }},
{ "match": { "content": "Elasticsearch" }}
],
"filter": [
{ "term": { "status": "published" }},
{ "range": { "publish_date": { "gte": "2015-01-01" }}}
]
}
}
}