[
https://issues.apache.org/jira/browse/CALCITE-4233?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17215328#comment-17215328
]
Shlok Srivastava edited comment on CALCITE-4233 at 10/22/20, 2:00 PM:
----------------------------------------------------------------------
I have raised an [initial PR |https://github.com/apache/calcite/pull/2218]for
dismax API support. As dismax API will be wrapping the filter/query within its
query node ({"query": {"dis_max": {) just like constant_score API, therefore I
am still confused on how to use it. Will it be ok if we use dismax whenever an
OR condition is present in the filter RelNode which can be governed from
PredicateAnalysers??
Following logic can be used -
{code:java}
boolean disMax = condition.isA(SqlKind.OR);
Iterator operands = ((RexCall) condition).getOperands().iterator();
while (operands.hasNext() && !disMax) {
if (operands.next().isA(SqlKind.OR))
{ disMax = true; break; }
}
if (disMax)
{
QueryBuilders.disMaxQueryBuilder(PredicateAnalyzer.analyze(condition)).writeJson(generator);
}
else
{
QueryBuilders.constantScoreQuery(PredicateAnalyzer.analyze(condition)).writeJson(generator);
}
{code}
was (Author: shlok7296):
I have raised an initial PR for dismax API support. As dismax API will be
wrapping the filter/query within its query node ({"query": {"dis_max": {) just
like constant_score API, therefore I am still confused on how to use it. Will
it be ok if we use dismax whenever an OR condition is present in the filter
RelNode which can be governed from PredicateAnalysers??
Following logic can be used -
{code:java}
boolean disMax = condition.isA(SqlKind.OR);
Iterator operands = ((RexCall) condition).getOperands().iterator();
while (operands.hasNext() && !disMax) {
if (operands.next().isA(SqlKind.OR))
{ disMax = true; break; }
}
if (disMax)
{
QueryBuilders.disMaxQueryBuilder(PredicateAnalyzer.analyze(condition)).writeJson(generator);
}
else
{
QueryBuilders.constantScoreQuery(PredicateAnalyzer.analyze(condition)).writeJson(generator);
}
{code}
> Elasticsearch Dismax API is not supported in calcite
> ----------------------------------------------------
>
> Key: CALCITE-4233
> URL: https://issues.apache.org/jira/browse/CALCITE-4233
> Project: Calcite
> Issue Type: Improvement
> Components: elasticsearch-adapter
> Reporter: Shlok Srivastava
> Priority: Major
> Labels: QueryBuilder, calcite, dismax, elasticsearch
>
> Currently, Calcite use constant_score API to build all the queries. which do
> not boost the documents based on relevance score from any matching clause
> which is supported by disMax API. It does not support dismax query builders -
> [https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-dis-max-query.html.]
>
> Dismax query -
> {code:java}
> GET /_search
> {
> "query": {
> "dis_max": {
> "queries": [
> {
> "bool": {
> "should": [
> {
> "term": {
> "Name": "James"
> }
> },
> {
> "term": {
> "Name": "Peter"
> }
> },
> {
> "term": {
> "Name": "Harry"
> }
> },
>
> }
> ]
> }
> ]
> }
> }{code}
> Suggested solution - Queries with OR conditions should use disMax builders
> to fetch the best matching documents.
>
> Sample SQL query -
> {code:java}
> WHERE Name="James" OR Name="Peter" OR Name="Harry" {code}
> Sample RelNode -
> {code:java}
> relB.or(relB.equals(relb.literal("Name"),relb.literal"James"),
> relB.equals(relb.literal("Name"),relb.literal"Peter"),
> relB.equals(relb.literal("Name"),relb.literal"Harry"){code}
--
This message was sent by Atlassian Jira
(v8.3.4#803005)