# Elasticsearch Nested Match Last Value

**URL:** <https://discuss.elastic.co/t/elasticsearch-nested-match-last-value/92219>\
**Category:** Elasticsearch\
**Created:** [July 7, 2017, 7:25am UTC](https://discuss.elastic.co/t/elasticsearch-nested-match-last-value/92219 "2017-07-07T07:25:06Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![muthuvel](https://avatars.discourse-cdn.com/v4/letter/m/aca169/32.png) [@muthuvel](https://discuss.elastic.co/u/muthuvel)\
**Post date:** [July 7, 2017, 7:25am UTC](https://discuss.elastic.co/t/elasticsearch-nested-match-last-value/92219/1 "2017-07-07T07:25:06Z")

</div>

We have article & edited authors as array. Need to check How many article last edited by particular author.

**_Data:_**

```
{
    "Article" : [
      {
        "id" : 12
        "title" : "An article title",
        "categories" : [1,3,5,7],
        "tag" : ["elasticsearch", "symfony",'Obtao'],
        "author" : [
            {
                "firstname" : "Francois",
                "surname": "francoisg",
                "id" : 18
            },
            {
                "firstname" : "Gregory",
                "surname" : "gregquat"
                "id" : "2"
            }
        ]
      }
    },
    {
        "id" : 13
        "title" : "A second article title",
        "categories" : [1,7],
        "tag" : ["elasticsearch", "symfony",'Obtao'],
        "author" : [
            {
                "firstname" : "Gregory",
                "surname" : "gregquat",
                "id" : "2"
            },
            {
                "firstname" : "Francois",
                "surname": "francoisg",
                "id" : 18
            }
        ]
      }
}

```

**_Request Data:_**  
URL: [http://localhost:9200/book/articles/\_count/](http://localhost:9200/book/articles/_count/)

```
For example `Gregory` & `Francois` should get one article as count.

```

Please let me know how to compare first object only & get results.

---

<div class="post-metadata">

**Author:** ![Tetrapack](https://avatars.discourse-cdn.com/v4/letter/t/85f322/32.png) [@Tetrapack](https://discuss.elastic.co/u/Tetrapack)\
**Post date:** [July 7, 2017, 1:09pm UTC](https://discuss.elastic.co/t/elasticsearch-nested-match-last-value/92219/2 "2017-07-07T13:09:54Z")

</div>

Hello,

I think you should add a property in your model in order to distinguish the first object of author's array.

As is, you can't make a request which target only the first element of an array.

If you don't need author's array mapped as "nested", you can eventually make a scripted request like this

```
GET /_search
{
    "query": {
        "bool" : {
            "must" : {
                "script" : {
                    "script" : {
                        "inline": "doc['author.firstname'][0] == params.searchedFirstName",
                        "lang": "painless",
                        "params":{
                                                 "searchedFirstName" : "Francois"
                          }
                     }
                }
            }
        }
    }
}

```

But without nested, you will not be able to search articles with author "Francois Francoisg"..  
([look a the doc about nested type](https://www.elastic.co/guide/en/elasticsearch/reference/current/nested.html))

---

<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:** [August 4, 2017, 1:10pm UTC](https://discuss.elastic.co/t/elasticsearch-nested-match-last-value/92219/3 "2017-08-04T13:10:08Z")

</div>

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