Searching based on last modified


(william crawley) #1

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.


(David Pilato) #2

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


(william crawley) #3

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 ......


(william crawley) #4

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


(system) #5

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