However I have certain fields to be searched with static criteria e.g. year as 2020,geoLocation within 20 miles etc
and some criteria to be added on various conditions e.g. year <2020 and height >4 feet (this is just an example)
Not sure how do I cater this requirement ie. Either use a SQL template as below and have place holder to inject (append) additional criterias in it through
java code or use RestHighLevelClient (Could not find such a realistic example through like relational ORM criteria api like Specification)
Here is how my template will look like and will be formed on the fly as per request
e.g. $DYNAMIC_PLACEHOLDERS$ will be added as below on the fly
{
"range" : {
"age": {
"gte": "$DOB$"
}
}
},
My Question : Is having such template and modifying as per request is good idea or is there any better way to deal with it and what about the performance is there any best practices in Elasticsearch ?
Elasticsearch does not have if/else in their templating engine. Only if a field is set you could add a block to the query.
If it is a dynamic query with dynamic fields and conditions I would recommend using it in code somewhere and build up the query there. But maybe I am getting the question wrong..
Here based on gender
e.g. if Male DYNAMIC_PLACEHOLDERS will be replaced with
{
"range": {
"LATITUDE": {
"gte": 5
}
}
},
AND
e.g. if FeMaleDYNAMIC_PLACEHOLDERS will be replaced with
{
"range": {
"LATITUDE": {
"gte": 4
}
}
},
Here replacing DYNAMIC_PLACEHOLDERS with above range constraint I am planning to handle in java code.Will this be a good idea and efficient way or is there
any better way to do it as I have many such dynamic conditions will require to be added based on request parameters ?
Are these values always present? What you could do is creating a search template and use parameters to change those values. Your application triggers the search. So in that case you can use the template and set the right values to the params.
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.