If I have a document with nested array, how can search nested array using elasticlunr? I get an empty array when search on city of Phoenix.
Following is my code example. Thanks,
const doc1 =
{
"id": 123,
"firstName": "jon",
"lastName": "doe",
"addresses": [
{
"line1": "123 any str",
"city": "Some City",
"state": "CA"
}
]
};
const doc2 {
"id": 456,
"firstName": "alan",
"lastName": "park",
"addresses": [
{
"line1": "1 some str",
"city": "Phoenix",
"state": "AZ"
}
]
}
this.index.addDoc(doc1);
this.index.addDoc(doc2);
let index = elasticlunr(function () {
this.addField('firstName');
this.addField('lastName');
this.addField('addresses');
this.addField('city');
this.addField('state');
this.setRef('id');
});
this.index = index;
searchFreeText() {
return this.index.search("Phoenix", {
fields: {
firstName: { boost: 1, bool: "OR", expand: true },
lastName: { boost: 1, bool: "OR" },
addresses: { boost: 1, bool: "OR" },
line1: { boost: 1, bool: "OR" },
city: { boost: 1, bool: "OR" },
state: { boost: 1, bool: "OR" },
}
});
}
Above is my code example.