Nested field support for index setup
See original GitHub issueWhen I have documents with a structure like:
{
name: "Some name",
address: {
street: "Main Street",
number: "42",
city: "Some Town"
}
}
I’d like to search among the city
field but I can only specify fields on the top level of the document when setting up my index:
var index = lunr(function () {
this.field('address')
});
It would be nice, if I could specify a nested field for indexing. Something like this:
var index = lunr(function () {
this.field('address.city');
//or maybe:
this.field(['address', 'city']);
});
Issue Analytics
- State:
- Created 8 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Nested field type | Elasticsearch Guide [8.5] | Elastic
The nested type is a specialised version of the object data type that allows arrays of objects to be indexed in a way...
Read more >Object Fields VS. Nested Field Types in Elasticsearch - Opster
Nested is a special type of object that is indexed as a separate document, and a reference to each of these inner documents...
Read more >Adding nested fields ( objects in array ) query support to ...
You need to go to the respective indexes and enable them. For doing that, go to Management -> Nested fields.
Read more >Nested - OpenSearch documentation
A nested field type is a special type of object field type. Any object field can take an array of objects. Each of...
Read more >Indexing Nested Documents :: Apache Solr Reference Guide
Example Indexing Syntax: Pseudo-Fields; Schema Configuration; Maintaining Integrity with Updates and Deletes; Indexing Anonymous Children. Solr supports ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This is a request that comes up quite a lot.
The reason I haven’t implemented this change is that I think it can (and should) be done outside of lunr, since the structure of the document is very specific to each user.
In your use case you would just need to have a conversion function that maps your document to something that can be indexed:
This also gives you the flexibility to combine certain fields into a single field to be indexed by lunr or doing any other conversion you want before lunr starts to index the fields.
@Petesta the search method does not return the documents that match, instead it returns a reference, i.e. the id of the document. The results are covered in more detail in the search results docs, they look like this: