Filter search with drill down approach using Java API

Hi All,

I need a help on drill down approach as i was successfully able to do the process at multi level search. The problem currently i am facing is my query gets generated twice for same option.

For eg : if i search on Price -> Title -> Color the generated query is

"bool" : {
"must" : [ {
"range" : {
"Price" : {
"from" : "52468",
"to" : "62353",
"include_lower" : true,
"include_upper" : false
}
}
}, {
"term" : {
"title" : "abc"
}
}, {
"term" : {
"color" : "white"
}
}]
}

the above query provides me a successful result.

If i change the color from white to red then the result is returned null and the query generated is

"bool" : {
"must" : [ {
"range" : {
"Price" : {
"from" : "52468",
"to" : "62353",
"include_lower" : true,
"include_upper" : false
}
}
}, {
"term" : {
"title" : "abc"
}
}, {
"term" : {
"color" : "white"
}
}, {
"term" : {
"color" : "red"
}
} ]
}

The query which is expected is

"bool" : { "must" : [ { "range" : { "Price" : { "from" : "52468", "to" : "62353", "include_lower" : true, "include_upper" : false } } }, { "term" : { "title" : "abc" } }, { "term" : { "color" : "red" } }] }

I tried using a json object which i was able to replace the color with red then the problem which occurred is i could not convert the string to QueryBuilder. I used WrapperQuery to convert string i got a encrypted data which i could not track forward it for query processing.

I have used BoolQueryBuilder for my approach.

Thanks

Why not create a new QueryBuilder? QueryBuilder instances should not be
preserved after it builds a query.

--
Ivan

On Mon, Nov 18, 2013 at 3:30 AM, kavesh kavesh.shetgaonkar@privail.comwrote:

Hi All,

I need a help on drill down approach as i was successfully able to do the
process at multi level search. The problem currently i am facing is my
query
gets generated twice for same option.

For eg : if i search on Price -> Title -> Color the generated query is
*
"bool" : {
"must" : [ {
"range" : {
"Price" : {
"from" : "52468",
"to" : "62353",
"include_lower" : true,
"include_upper" : false
}
}
}, {
"term" : {
"title" : "abc"
}
}, {
"term" : {
"color" : "white"
}
}]
}*

the above query provides me a successful result.

If i change the color from white to red then the result is returned null
and
the query generated is

  • "bool" : {
    "must" : [ {
    "range" : {
    "Price" : {
    "from" : "52468",
    "to" : "62353",
    "include_lower" : true,
    "include_upper" : false
    }
    }
    }, {
    "term" : {
    "title" : "abc"
    }
    }, {
    "term" : {
    "color" : "white"
    }
    }, {
    "term" : {
    "color" : "red"
    }
    } ]
    }*

The query which is expected is

"bool" : {
"must" : [ {
"range" : {
"Price" : {
"from" : "52468",
"to" : "62353",
"include_lower" : true,
"include_upper" : false
}
}
}, {
"term" : {
"title" : "abc"
}
}, {
"term" : {
"color" : "red"
}
}]
}*

I tried using a json object which i was able to replace the color with red
then the problem which occurred is i could not convert the string to
QueryBuilder
. I used WrapperQuery to convert string i got a encrypted
data which i could not track forward it for query processing.

I have used BoolQueryBuilder for my approach.

Thanks

--
View this message in context:
http://elasticsearch-users.115913.n3.nabble.com/Filter-search-with-drill-down-approach-using-Java-API-tp4044468.html
Sent from the Elasticsearch Users mailing list archive at Nabble.com.

--
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 Ivan,

Can you please let me know why we should not preserve the QueryBuilder instances? QueryBuilder will always give me result for the selected value.

Can you please give an idea how to go about.

My requirement is if i am searching on title then all results with title should be displayed. if i am adding a filter saying color then the result should be title+color combined result should be displayed.

Thanks

Why not reuse a QueryBuilder instance? Because you will find yourself in
the exact situation you are in. The Builder design pattern in general is
not meant for reuse.

Without looking at your code, I am assuming you are adding must clauses to
a BoolQueryBuilder via the must() method:
https://github.com/elasticsearch/elasticsearch/blob/master/src/main/java/org/elasticsearch/index/query/BoolQueryBuilder.java#L53-56

Internally the mustClauses are a list, not some type of map with the field
name used as a key. There is no remove method, resetting of the clauses, or
direct accesses to the clauses. That would not be part of the Builder
design pattern.

Cheers.

Ivan

On Mon, Nov 18, 2013 at 9:17 PM, kavesh kavesh.shetgaonkar@privail.comwrote:

HI Ivan,

Can you please let me know why we should not preserve the QueryBuilder
instances? QueryBuilder will always give me result for the selected value.

Can you please give an idea how to go about.

My requirement is if i am searching on title then all results with title
should be displayed. if i am adding a filter saying color then the result
should be title+color combined result should be displayed.

Thanks

--
View this message in context:
http://elasticsearch-users.115913.n3.nabble.com/Filter-search-with-drill-down-approach-using-Java-API-tp4044468p4044509.html
Sent from the Elasticsearch Users mailing list archive at Nabble.com.

--
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.

Can you please let me know what is the best possible solution that i can use for my approach. As i have tried with lot of procedures and dint come up to the solution yet.

Thanks

I never said to not use the QueryBuilders*, *I said to not RE-use them. Do
not preserve them or change them after a query, simply create a new one.

--
Ivan

On Tue, Nov 19, 2013 at 2:45 AM, kavesh kavesh.shetgaonkar@privail.comwrote:

Thanks Ivan. For the clarification on why not to use QueryBuilder.

Can you please let me know what is the best possible solution that i can
use
for my approach. As i have tried with lot of procedures and dint come up to
the solution yet.

Thanks

--
View this message in context:
http://elasticsearch-users.115913.n3.nabble.com/Filter-search-with-drill-down-approach-using-Java-API-tp4044468p4044529.html
Sent from the Elasticsearch Users mailing list archive at Nabble.com.

--
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.