I have an ElasticSearch query that looks like this:
{
"query": {
"query_string": {
"query": "Lorem*",
"fields": ["search_names", "name^2"]
}
}
}
Against documents that look like this.
{
"member_name" : "Lorem Ipsum",
"complaint_periods" : [
{
"period": "01/01/2001 - 31/12/2001",
"complaints": "10"
},
{
"period": "01/01/2002 - 31/12/2002",
"complaints": "0"
},
{
"period": "01/01/2003 - 31/12/2003",
"complaints": "3"
},
{
"period": "01/01/2004 - 31/12/2004",
"complaints": "100"
}
],
"search_names" : [
"Lorem Ipsum",
"dolor sit amet",
"varius augue",
"Aliquam fringilla"
]
}
So I'm able to retrieve documents based on how close their name, and search names are to my query.
The requirement is, a text search box should retrieve the closest name match to the query, however, given relatively similar names, a document with a number of complaints above a threshold of 10 in a passed time period, should appear higher in the search results than those with less than 10.
So I need to pass a key for the time period, e.g. "01/01/2001 - 31/12/2001", and boost the documents score if the complaint value for that period is > 10.
Current index mapping looks like this.
"mappings": {
"properties": {
"member_name": {
"type": "text"
},
"search_names": {
"type": "text"
},
"complaint_periods": {
"type": "nested",
"properties": {
"period": {
"type": "text",
},
"complaints": {
"type": "integer"
}
}
}
}
}
I'm currently reading into Nested queries as a possible solution...but I'm fairly fresh to ES so keen to get opinions on the types of queries/structure I should be using to achieve this.
Any advice?
Thank you.