0

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.

Val
  • 207,596
  • 13
  • 358
  • 360
Maharaj
  • 313
  • 2
  • 3
  • 14
  • If I'm not mistaken elasticlunr has nothing to do with Elasticsearch, so I've removed the tag – Val Mar 08 '23 at 04:27
  • @val you are correct, elasticlunr has nothing to do with Elasticsearch. I couldn't create a new tag for elasticlunr since I don't have enough badges or points in stackoverflow. Thanks for adding one. – Maharaj Mar 09 '23 at 14:24

0 Answers0