Skip to content

Instantly share code, notes, and snippets.

@aliostad
Created October 26, 2014 13:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aliostad/233f48e897f9dd2693a5 to your computer and use it in GitHub Desktop.
Save aliostad/233f48e897f9dd2693a5 to your computer and use it in GitHub Desktop.
elasticsearch snippets

Sort and define numbers to return

{
	"query": {"match_all" :{}}
    ,
	"size": 10,
	"sort": { "PubDate":{ "order": "desc" }}
}

Aggregate by cat

{
	"query": {"match_all" :{}}
    ,
	"size": 0,
	"aggs": {
        "ChannelCategory": {
          "terms": {
            "field": "ChannelCategory"
          }
        }
    }
}

Mixing filter

{
    "query": {
        "filtered": {
            "query": {
                "match_all": {}
            },
            "filter": {
                "bool": {
                	"must":{
                    "term": {
                        "ChannelCategory": "main"
                    }}
                }
            }
        }
    },
    "size": 0,
    "aggs": {
        "ChannelCategory": {
            "terms": {
                "field": "ChannelCategory"
            }
        }
    }
}

Modifying a field and formatting it using Script

{
    "query" :
       {"term":{"text":"isis"}},
       "_source":true,
       "script_fields" : {
        "test1" : {
            "script" : "doc['id'].value * 2"
        }}


}

===

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment