I have a big document with a requirement to dynamically search
E.g. Student
{
id,
name,
Address,
Associated_Subjects
phone,
home_phone,
mobile,
year,
dob,
geolocation:(lat/long)
height
.
.
.
etc
}
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
"bool": {
"must": [
{
"match": {
"Associated_Subjects": $SUBJECT$
}
}
],
"filter": [
$DYNAMIC_PLACEHOLDERS$
{
"geo_distance": {
"distance": "$DISTANCE_RADIUS$",
"location": {
"lat": $LATITUDE$,
"lon": $LONGITUDE$
}
}
},
{
"range" : {
"dob": {
"gte": "$DOB$"
}
}
}
]
}
}
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 elastic search ?