# Searching multifield with nested object not working in the nested object

**URL:** <https://discuss.elastic.co/t/searching-multifield-with-nested-object-not-working-in-the-nested-object/254623>\
**Category:** Elasticsearch\
**Created:** [November 7, 2020, 3:54pm UTC](https://discuss.elastic.co/t/searching-multifield-with-nested-object-not-working-in-the-nested-object/254623 "2020-11-07T15:54:35Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Diogo\_Filipe](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/diogo_filipe/32/78609_2.png) [@Diogo\_Filipe](https://discuss.elastic.co/u/Diogo_Filipe)\
**Post date:** [November 7, 2020, 3:54pm UTC](https://discuss.elastic.co/t/searching-multifield-with-nested-object-not-working-in-the-nested-object/254623/1 "2020-11-07T15:54:35Z")

</div>

Hi,

I'm using Elastic 7.9.2 with ECK 1.2.1. Using Java and Spring too.

I'm trying to query a nested object directly to the id variable(inside the 2nd object) but it always returns zero results.

An example of my mapping, **model\_objects** is the nested object:

```auto
"mappings": {
    "properties": {
      "id": {
        "type": "keyword"
      },
      "date": {
        "type": "long"
      },
      "user_id": {
        "type": "keyword"
      }
      "model_objects": {
        "type": "nested",
        "properties": {
          "id": {
            "type": "keyword"
          },
          "name": {
            "type": "keyword",
            "index": false
          }
       }
    }
}
```

Then this will map to this objects:

```auto
public class MessageFromCore {
    private String id;
    private long date;
    private String user_id;
    private List<ModelObjects> model_objects;
}
```

and

```auto
public class ModelObjects {
    private String id;
    private String name;

    public ModelObjects(String id, String name) {
        this.id = id;
        this.name = name;
    }
}
```

This is indexing and working good for almost everything even search on other parameters except, when I try to search for objects that have a given id to search inside the **model\_objects** , then it always returns an empty response.  
The part of the search that is not working is this:

```auto
if (messageFromFront.getModel_id() != null) {
   ((BoolQueryBuilder) qb).must(QueryBuilders.termsQuery("model_objects.id", messageFromFront.getModel_id()));
}
//getModel_id() returns a List<String>
```

This QueryBuilders should work like this according to the documentation or I didn't understand or I'm not seeing something.

I have other QueryBuilders in the same method in other ifs to add to the query and all work together and simultaneously except when I put a model\_objects to be searched.

I tried to search for other ways and couldn't find anything that works for me.

Let me know if I need to provide anything else that could help me solve this.  
Thank you  
Diogo

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [December 5, 2020, 3:54pm UTC](https://discuss.elastic.co/t/searching-multifield-with-nested-object-not-working-in-the-nested-object/254623/2 "2020-12-05T15:54:36Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
