# How to improve search?

**URL:** <https://community.forestadmin.com/t/how-to-improve-search/5673>\
**Category:** Help me!\
**Created:** [December 7, 2022, 2:48pm UTC](https://community.forestadmin.com/t/how-to-improve-search/5673 "2022-12-07T14:48:38Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![alex42](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/alex42/32/4212_2.png) [@alex42](https://community.forestadmin.com/u/alex42)\
**Post date:** [December 7, 2022, 2:48pm UTC](https://community.forestadmin.com/t/how-to-improve-search/5673/1 "2022-12-07T14:48:38Z")

</div>

## Feature(s) impacted

Search

## Observed behavior

Search don’t work on nested fields…

## Expected behavior

How to enable search on nested fields?

## Context

Hello,

I’m using forest admin with mongodb, and I’m wondering how to enable or how to add code to provide a search on nested fields? See example:

**I’ve 2 collections**

- Users (each user is linked to a family with an ID)
- Family
- ID
- Name

How to provide search from Users collection with the family name? from this input: (without advanced filters)

![image](https://europe1.discourse-cdn.com/flex013/uploads/forest/original/2X/4/430187cbfd7516d201798bc85961bad9d876e9f6.png)

Thanks for your help,  
Alexandre

---

<div class="post-metadata">

**Author:** ![anon39940173](https://avatars.discourse-cdn.com/v4/letter/a/8c91f0/32.png) [@anon39940173](https://community.forestadmin.com/u/anon39940173)\
**Post date:** [December 7, 2022, 3:07pm UTC](https://community.forestadmin.com/t/how-to-improve-search/5673/2 "2022-12-07T15:07:48Z")

</div>

That depends on which agent you are using.

With `@forestadmin/agent` (released last july), search can be customized by passing a custom handler to the `replaceSearch` method.

Here is the documentation: [https://docs.forestadmin.com/developer-guide-agents-nodejs/agent-customization/search](https://docs.forestadmin.com/developer-guide-agents-nodejs/agent-customization/search)

With `forest-express`, the API is much lower level, and customers were expected to override the list route, and implement their own behavior there.

Here is the documentation: [https://docs.forestadmin.com/documentation/reference-guide/routes](https://docs.forestadmin.com/documentation/reference-guide/routes)

---

<div class="post-metadata">

**Author:** ![alex42](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/alex42/32/4212_2.png) [@alex42](https://community.forestadmin.com/u/alex42)\
**Post date:** [December 7, 2022, 4:48pm UTC](https://community.forestadmin.com/t/how-to-improve-search/5673/3 "2022-12-07T16:48:08Z")

</div>

Hello Romain!

Thanks for your quick response, I’m using forest-express-mongoose, so I need to use [https://docs.forestadmin.com/documentation/reference-guide/routes](https://docs.forestadmin.com/documentation/reference-guide/routes) right?

And did you have any example of implementation ?

Thanks,  
Alex

---

<div class="post-metadata">

**Author:** ![alex42](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/alex42/32/4212_2.png) [@alex42](https://community.forestadmin.com/u/alex42)\
**Post date:** [December 28, 2022, 1:49pm UTC](https://community.forestadmin.com/t/how-to-improve-search/5673/4 "2022-12-28T13:49:56Z")

</div>

Hello,

Any help on this topic? It’s really ruining our experience with Forest…

Thanks,  
Alex

---

<div class="post-metadata">

**Author:** ![anon39848301](https://avatars.discourse-cdn.com/v4/letter/a/b9e5f3/32.png) [@anon39848301](https://community.forestadmin.com/u/anon39848301)\
**Post date:** [January 2, 2023, 9:28am UTC](https://community.forestadmin.com/t/how-to-improve-search/5673/6 "2023-01-02T09:28:59Z")

</div>

Hey @alex42 👋, and sorry for the super delayed response.

> I’m using forest-express-mongoose

Are you using the `fields flattener` feature to deal with your nested fields ?  
([https://docs.forestadmin.com/documentation/how-tos/setup/flatten-nested-fields-mongodb](https://docs.forestadmin.com/documentation/how-tos/setup/flatten-nested-fields-mongodb))

---

<div class="post-metadata">

**Author:** ![alex42](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/alex42/32/4212_2.png) [@alex42](https://community.forestadmin.com/u/alex42)\
**Post date:** [January 5, 2023, 1:40pm UTC](https://community.forestadmin.com/t/how-to-improve-search/5673/7 "2023-01-05T13:40:08Z")

</div>

Hello @anon39848301,

Thanks for your reply, my issue is more with populated (from other collections) fields (who are not searchable) and not about flattened fields (I guess)

To re-explain my problem, the “Account number” field is populated from another collection, but when I search “Himalia” in the search I got 0 results…

 ![image](https://europe1.discourse-cdn.com/flex013/uploads/forest/original/2X/0/04cffd1ed953822dcbe6031953b47d52de4e9e64.png)

Thanks a lot for your help

---

<div class="post-metadata">

**Author:** ![anon39848301](https://avatars.discourse-cdn.com/v4/letter/a/b9e5f3/32.png) [@anon39848301](https://community.forestadmin.com/u/anon39848301)\
**Post date:** [January 6, 2023, 10:27am UTC](https://community.forestadmin.com/t/how-to-improve-search/5673/8 "2023-01-06T10:27:25Z")

</div>

Did you try with the `extended search` feature?  
 ![image](https://europe1.discourse-cdn.com/flex013/uploads/forest/original/2X/f/ff17fd261d27008d4b3f5c1405b61d7234a2b728.png)

By default, search only works on the default fields available for your specific model, and `extended search` allow you to search inside `belongsTo` relations.

If it doesn’t work, a [smart field](https://docs.forestadmin.com/documentation/reference-guide/smart-fields) referencing the field you want to search on + [an implementation of the associated search](https://docs.forestadmin.com/documentation/reference-guide/smart-fields#searching-sorting-and-filtering-on-a-smart-field) could do the trick here.
