My ElasticSearch documents contain a nested collection of form fields. Each field has a name and a value and the mapping is as follows:
form: {
properties: {
id: { type: 'integer' },
name: { type: 'text' },
form_data: {
type: 'nested',
properties: {
'name': { type: 'keyword' },
'value': { type: 'text', analyzer: 'full_text_analyzer' }
}
}
}
}
I need to allow the user to search for multiple form fields to refine their search. They can choose which fields to search by and assign a value to each. For example
applicant_name = 'Joe'
pet_type = 'dog'
This would find all documents that contained a field named applicant_name which had a value fuzzy matching Joe as well as a field named pet_type and a value fuzzy matching dog.
The query I'm trying to do this with is as follows.:
{
"query": {
"bool": {
"must": [{
"nested": {
"path": "form_data",
"query": {
"filter": {
"bool": {
"must": [
{
"bool": {
"must": [
{ "term": { "form_data.name": "applicant_name" } },
{ "match": { "form_data.value": "Joe" } }
]
}
},
{
"bool": {
"must": [
{ "term": { "form_data.name": "pet_type" } },
{ "match": { "form_data.value": "dog" } }
]
}
}
]
}
}
}
}
}]
}
}
}
However, I get 0 results.