Skip to content

Instantly share code, notes, and snippets.

@claudiu-stanciu
Last active April 1, 2021 09:59
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 claudiu-stanciu/c8ea39f192575f9299a6c7dae2e85085 to your computer and use it in GitHub Desktop.
Save claudiu-stanciu/c8ea39f192575f9299a6c7dae2e85085 to your computer and use it in GitHub Desktop.
Elasticsearch queries

search docs where fields match

GET <host>:<port>/<index>/_search
Body:
{
  "query": {
    "bool": {
      "filter": {
        "script": {
          "script": "doc['field_a'].value == doc['field_b'].value"
        }
      }
    }
  }
}

search docs where fields match, and count them

POST <host>:<port>/<index>/_search?size=0
{
  "query": {
    "bool": {
      "filter": {
        "script": {
          "script": "doc['field_a'].value == doc['field_b'].value"
        }
      }
    }
  },
  "aggs": {
    "type_count": {
      "value_count": { "field" : "field_a" }
    }
	}
}

delete all docs using query

POST <host>:<port>/<index>/_delete_by_query
Body:
{
  "query": {
    "bool": {
      "filter": {
        "script": {
          "script": "doc['field_a'].value == doc['field_b'].value"
        }
      }
    }
  }
}

count documents

GET <host>:<port>/<index>/_count
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment