Reactivesearch: Feature: Add support for `nested` object mapping

Created on 31 Oct 2018  路  11Comments  路  Source: appbaseio/reactivesearch

Issue Type:

Enhancement

Platform:

ReactiveSearch for Web

Description:

ReactiveSearch today doesn't support querying the fields of an object field with a nested mapping.

A nested object requires a different query (where a path for the nested field needs to be specified) along with the original query. The same applies to an aggregation.

This issue proposes to add a nestedField prop in all the data-driven components we have to support the use-case of a nested object.

Prop definition for the field looks like:

nestedField String [optional]
When your dataField is present inside an object of type nested, this can be used to set the path of the nested field. Setting this allows searching within documents belonging to the path.

Reactivesearch version: x.y.z

2.12.1

Components to support this in:

  • [x] MultiDropdownList
  • [x] SingleDropdownList
  • [x] MultiList
  • [x] SingleList
  • [ ] SingleRange
  • [ ] MultiRange
  • [ ] SingleDropdownRange
  • [ ] MultiDropdownRange
  • [ ] DataSearch
  • [ ] CategorySearch
  • [ ] TextField
  • [ ] ToggleButton
  • [ ] TagCloud
  • [ ] SingleDataList
  • [ ] MultiDataList
  • [ ] RangeSlider
  • [ ] DynamicRangeSlider
  • [ ] RangeInput
  • [ ] NumberBox
  • [ ] DatePicker
  • [ ] DateRange
  • [ ] RatingsFilter
  • [ ] GeoDistanceSlider
  • [ ] GeoDistanceDropdown
Vue.JS enhancement good first issue help wanted

Most helpful comment

@metagrover I've redone my changes in MultiList.

My previous idea was to store "nested" part of property name in nestedField
i.e. vendor is nested object with field name

dataField: 'name'
nestedField: 'vendor'

(it was some time before your changes for nested mapping support)

Now, I've followed your guidelines and made it your way:

dataField: 'vendor.name'
nestedField: 'vendor'

tested it with my local ES instance of my project. Everyting works like a charm! Finally I do not need a patched reactivesearch, hooray! ;)

All 11 comments

@metagrover here is my contrib for nested fields in MultiList. Should I make a PR?

https://github.com/aol-nnov/reactivesearch/commit/a797ba6097d3c9bcee8be5a5729d9d1caeb8cff9

@aol-nnov Left the reviews on the commit. Thanks for taking out the time to work on this!

Thanks, I'll revisit the changes soon.

It worked for me months before, but I was never confident if it's a clear fix for nested fields.

@metagrover I've redone my changes in MultiList.

My previous idea was to store "nested" part of property name in nestedField
i.e. vendor is nested object with field name

dataField: 'name'
nestedField: 'vendor'

(it was some time before your changes for nested mapping support)

Now, I've followed your guidelines and made it your way:

dataField: 'vendor.name'
nestedField: 'vendor'

tested it with my local ES instance of my project. Everyting works like a charm! Finally I do not need a patched reactivesearch, hooray! ;)

~~@metagrover I've just noticed a weird thing: terms in MultiList are displayed fine, but if I tick one (or several) of them, results in the ResultCard are not filtered.

Any clue what I've missed? (It was working fine with my approach you reviewed yesterday)~~

Oh, please disregard this. It's me again. Everything is okay with this patch.

Probably something's off with the defaultQuery. Check if the final query is being wrapped by nested query?

I'm looking into this!

no need to.. It was me again ). I've updated the comment (strike through was not applied though)

Hey guys, thanks for this, really helpful!
Here follows an observation: One nested property is allowed to have another nested one inside it. This API doesn't support that case.

Since it is a new API, wouldn't it be appropriate to consider an API definition which enables this "recursion" into the appropriate nested level?

I believe its a corner case, but i've come to it recently:
```
{
nested: {
path: 'trajectory',
query: {
nested: {
path: 'trajectory.company',
query: {
simple_query_string: {
query: value,
fields: ['trajectory.company.name'],
},
},
},
},
},
}

@TCMiranda This is a must-have.

Consider such documents:

{
  nestedArrayField: [
    {
      nestedTranslatedField: {
        code: "some_string",
        en: "SomeString",
        fi: "JokinMerkkijono"
      }
    },
    {
      nestedTranslatedField: {
        code: "some_other_string",
        en: "SomeOtherString",
        fi: "JokinMuuMerkkijono"
      }
    }
  ]
}

Currently, it doesn't seem to be possible to use values from the nested translated field.

@MarttiR You can achieve this via customQuery prop, where you can pass the QueryDSL directly.

@siddharthlatest I believe you can, but components are not prepared for that. They lack the option to map responses to internal features, like the dropdown options, the range histogram, etc.

Making it impossible to work with standard components just by using customQuery.

Disclosure: it has been some time since I worked with this library, so I'm not sure it is solved.
At the time we faced this issue, we created a parser using a serviceWorker to translate a special syntax we defined to deal with "nested" nested fields.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

calebdel picture calebdel  路  4Comments

tiagogm picture tiagogm  路  3Comments

rbeers picture rbeers  路  3Comments

danielsnider picture danielsnider  路  4Comments

metagrover picture metagrover  路  4Comments