2

I am using elastic search 2.3 version in my java project. I want to execute the following sql query for elastic search -

select fileName from (select distinct fileName from explore_object_metadata order by original_size desc)where rownum <=10

For this I try -

 client.prepareSearch()
                    .setIndices()
                    .setTypes(getType())
                    .addSort(fieldSort("sourceSize").order(DESC))
                    .setScroll(new TimeValue(ES_TIMEOUT_MS))
                    .setSize(10);

But it gives me 10 result in descending order with repeated fileName multiple times. What can I do to get top 10 records with unique filename and sorted in descending order by their size in elastic search.

1 Answer 1

1

Sense query to get the above query is -

{ 

  "aggs": {
    "id1_count": {
      "terms": { "field": "empname" ,
      "order": {
          "Max_Marks": "desc"
        }
      },

      "aggs": {
        "Max_Marks": {
          "max": {
            "field": "marks"
          }
        },
        "min_marks":{
            "min":{
                "field":"marks"
            }
        }
      }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.