Boosting results at query time using java api

Hi,
I am new to ES and trying to search using java apis. I am unable to figure
out how I can provide filed specific boosting using the java apis.
Here is the example:
My index document looks like:

_source": {

  • "th_id": 1,
  • "th_name": "test name",
  • "th_description": "test desc",
  • "th_image": "test-img",
  • "th_slug": "Make-Me-Smart",
  • "th_show_title": "Coast Tech Podcast",
  • "th_sh_category": "Alternative Health

}

When i search for keywords I want to boost the results higher if they found
in the "th_name" compared to they're found in some other fields.
Currently I am using below code to do search:
QueryBuilder qb1 = QueryBuilders.matchAllQuery();
FilterBuilder fb = FilterBuilders.orFilter(
FilterBuilders.termFilter("th_name", keyword),
FilterBuilders.termFilter("th_description", keyword),
FilterBuilders.termFilter("th_show_title", keyword),
FilterBuilders.termFilter("th_sh_category", keyword)
);

    // WildcardQueryBuilder wqb = new WildcardQueryBuilder(name, 

wildcard)
log.info("Executing Query: " + qb1.toString());
SearchResponse response =
client.prepareSearch("talk").setTypes("themes")

.setSearchType(SearchType.DFS_QUERY_THEN_FETCH).setQuery(qb1).setFilter(fb)
.setFrom(start).setSize(maxRows)
.setExplain(true).execute().actionGet();

Is there anything I can do at query time to boost the document if the
keyword is found in "th_name" field compared to found in other fields?

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Filters are not used for scoring. They only said 'yes' or 'no'!
If you want to use boost, use queries, not filters.

Does it help?

--
David :wink:
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

Le 13 mars 2013 à 22:40, Amit Patel avpatel.257@gmail.com a écrit :

Hi,
I am new to ES and trying to search using java apis. I am unable to figure out how I can provide filed specific boosting using the java apis.
Here is the example:
My index document looks like:

_source": {
"th_id": 1,
"th_name": "test name",
"th_description": "test desc",
"th_image": "test-img",
"th_slug": "Make-Me-Smart",
"th_show_title": "Coast Tech Podcast",
"th_sh_category": "Alternative Health
}

When i search for keywords I want to boost the results higher if they found in the "th_name" compared to they're found in some other fields.
Currently I am using below code to do search:
QueryBuilder qb1 = QueryBuilders.matchAllQuery();
FilterBuilder fb = FilterBuilders.orFilter(
FilterBuilders.termFilter("th_name", keyword),
FilterBuilders.termFilter("th_description", keyword),
FilterBuilders.termFilter("th_show_title", keyword),
FilterBuilders.termFilter("th_sh_category", keyword)
);

    // WildcardQueryBuilder wqb = new WildcardQueryBuilder(name, wildcard)
    log.info("Executing Query: " + qb1.toString());
    SearchResponse response = client.prepareSearch("talk").setTypes("themes")
        .setSearchType(SearchType.DFS_QUERY_THEN_FETCH).setQuery(qb1).setFilter(fb)
        .setFrom(start).setSize(maxRows)
        .setExplain(true).execute().actionGet();

Is there anything I can do at query time to boost the document if the keyword is found in "th_name" field compared to found in other fields?

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Hi,

David is right, and the java api documentation shows you exactly how to do
that :
Elasticsearch Platform — Find real-time answers at scale | Elastic in
the BoostingQuery part.

Regards,

Olivier.

Le jeudi 14 mars 2013 07:56:57 UTC+1, David Pilato a écrit :

Filters are not used for scoring. They only said 'yes' or 'no'!
If you want to use boost, use queries, not filters.

Does it help?

--
David :wink:
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

Le 13 mars 2013 à 22:40, Amit Patel <avpat...@gmail.com <javascript:>> a
écrit :

Hi,
I am new to ES and trying to search using java apis. I am unable to figure
out how I can provide filed specific boosting using the java apis.
Here is the example:
My index document looks like:

_source": {

  • "th_id": 1,
  • "th_name": "test name",
  • "th_description": "test desc",
  • "th_image": "test-img",
  • "th_slug": "Make-Me-Smart",
  • "th_show_title": "Coast Tech Podcast",
  • "th_sh_category": "Alternative Health

}

When i search for keywords I want to boost the results higher if they
found in the "th_name" compared to they're found in some other fields.
Currently I am using below code to do search:
QueryBuilder qb1 = QueryBuilders.matchAllQuery();
FilterBuilder fb = FilterBuilders.orFilter(
FilterBuilders.termFilter("th_name", keyword),
FilterBuilders.termFilter("th_description", keyword),
FilterBuilders.termFilter("th_show_title", keyword),
FilterBuilders.termFilter("th_sh_category", keyword)
);

    // WildcardQueryBuilder wqb = new WildcardQueryBuilder(name, 

wildcard)
log.info("Executing Query: " + qb1.toString());
SearchResponse response =
client.prepareSearch("talk").setTypes("themes")

.setSearchType(SearchType.DFS_QUERY_THEN_FETCH).setQuery(qb1).setFilter(fb)
.setFrom(start).setSize(maxRows)
.setExplain(true).execute().actionGet();

Is there anything I can do at query time to boost the document if the
keyword is found in "th_name" field compared to found in other fields?

--
You received this message because you are subscribed to the Google Groups
"elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to elasticsearc...@googlegroups.com <javascript:>.
For more options, visit https://groups.google.com/groups/opt_out.

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Thanks David and Olivier for your help.
I've changed my query builder to :
QueryBuilder qb1 = QueryBuilders.multiMatchQuery(keyword, "th_name",
"th_description", "th_show_title", "th_sh_category");

And now its only searching through the given list of fileds.

And I guess I would have to change the query builder to :
QueryBuilder qb2 =
QueryBuilders.boostingQuery().positive(QueryBuilders.termQuery("th_name",
keyword))
.negative(QueryBuilders.multiMatchQuery(keyword,
"th_description", "th_show_title", "th_sh_category")).negativeBoost(0.2f);

to make the boosting work.

On Thursday, March 14, 2013 9:23:25 AM UTC-4, Olivier Girardot wrote:

Hi,

David is right, and the java api documentation shows you exactly how to do
that :
Elasticsearch Platform — Find real-time answers at scale | Elastic in
the BoostingQuery part.

Regards,

Olivier.

Le jeudi 14 mars 2013 07:56:57 UTC+1, David Pilato a écrit :

Filters are not used for scoring. They only said 'yes' or 'no'!
If you want to use boost, use queries, not filters.

Does it help?

--
David :wink:
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

Le 13 mars 2013 à 22:40, Amit Patel avpat...@gmail.com a écrit :

Hi,
I am new to ES and trying to search using java apis. I am unable to
figure out how I can provide filed specific boosting using the java apis.
Here is the example:
My index document looks like:

_source": {

  • "th_id": 1,
  • "th_name": "test name",
  • "th_description": "test desc",
  • "th_image": "test-img",
  • "th_slug": "Make-Me-Smart",
  • "th_show_title": "Coast Tech Podcast",
  • "th_sh_category": "Alternative Health

}

When i search for keywords I want to boost the results higher if they
found in the "th_name" compared to they're found in some other fields.
Currently I am using below code to do search:
QueryBuilder qb1 = QueryBuilders.matchAllQuery();
FilterBuilder fb = FilterBuilders.orFilter(
FilterBuilders.termFilter("th_name", keyword),
FilterBuilders.termFilter("th_description", keyword),
FilterBuilders.termFilter("th_show_title", keyword),
FilterBuilders.termFilter("th_sh_category", keyword)
);

    // WildcardQueryBuilder wqb = new WildcardQueryBuilder(name, 

wildcard)
log.info("Executing Query: " + qb1.toString());
SearchResponse response =
client.prepareSearch("talk").setTypes("themes")

.setSearchType(SearchType.DFS_QUERY_THEN_FETCH).setQuery(qb1).setFilter(fb)
.setFrom(start).setSize(maxRows)
.setExplain(true).execute().actionGet();

Is there anything I can do at query time to boost the document if the
keyword is found in "th_name" field compared to found in other fields?

--
You received this message because you are subscribed to the Google Groups
"elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to elasticsearc...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.