# Searching based on last modified

**URL:** <https://discuss.elastic.co/t/searching-based-on-last-modified/96079>\
**Category:** Elasticsearch\
**Created:** [August 7, 2017, 10:00am UTC](https://discuss.elastic.co/t/searching-based-on-last-modified/96079 "2017-08-07T10:00:23Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![bilpor](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bilpor/32/24043_2.png) [@bilpor](https://discuss.elastic.co/u/bilpor)\
**Post date:** [August 7, 2017, 10:00am UTC](https://discuss.elastic.co/t/searching-based-on-last-modified/96079/1 "2017-08-07T10:00:23Z")

</div>

Hi All,

I have Elasticsearch 5.5.1 running with Fscrawler. My initial searches based on document content are working, using a search in the form:

```
`GET myindex/_search?q='Large profitable'&filter_path=hits.hits._source.path.real.`

```

I now need a to perform a search that just returns say the last 10 documents modified. in the index and I don't care about the content. Can anyone suggest how I'd do this query.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [August 7, 2017, 10:31am UTC](https://discuss.elastic.co/t/searching-based-on-last-modified/96079/2 "2017-08-07T10:31:05Z")

</div>

Have a look at Sort: [https://www.elastic.co/guide/en/elasticsearch/reference/5.5/search-request-sort.html](https://www.elastic.co/guide/en/elasticsearch/reference/5.5/search-request-sort.html)

---

<div class="post-metadata">

**Author:** ![bilpor](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bilpor/32/24043_2.png) [@bilpor](https://discuss.elastic.co/u/bilpor)\
**Post date:** [August 7, 2017, 11:07am UTC](https://discuss.elastic.co/t/searching-based-on-last-modified/96079/3 "2017-08-07T11:07:49Z")

</div>

I changed my mappings to include a property post\_date so that it now looks like this:

```
PUT myindex
{
  "settings" : {
    "number_of_shards" : 3,
    "number_of_replicas" : 2
  },
  "mappings" : {
    "myprop" : {
      "properties" : {
        "post_date": {"type": "date", "store" : true},
        "data" : {
          "type": "text"
        }
      }
    }
  }
}

```

I run fscrawler with the `--restart` option

Now if I run the following, then the sort doesn't do anything. I can change the order or the mode I receive all documents always in the same order:

```
GET myindex/_search
{ "query" : {

    "match_all" : { }},
    "sort" : [
      { "post_date": {"order" : "desc", "mode": "min"}}
    ]
}    

```

Although min & max should return a single item based on the order it doesn't. Even if I manage to get this working, I still cant find anything that will give me the SQL equivalent of `Select top 10 ......`

---

<div class="post-metadata">

**Author:** ![bilpor](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bilpor/32/24043_2.png) [@bilpor](https://discuss.elastic.co/u/bilpor)\
**Post date:** [August 7, 2017, 2:33pm UTC](https://discuss.elastic.co/t/searching-based-on-last-modified/96079/4 "2017-08-07T14:33:06Z")

</div>

I managed to resolve this by removing the **post\_date** property on the mapping, then using the following query. I was trying to map sort in the same way as the filter (on the node hierarchy) which was incorrect even though nothing complained:

`GET myindex/_search?q=content:*&filter_path=hits.hits._source.path.real&sort=file.last_modified:desc&size=10`

---

<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:** [September 4, 2017, 2:33pm UTC](https://discuss.elastic.co/t/searching-based-on-last-modified/96079/5 "2017-09-04T14:33:08Z")

</div>

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