-
Notifications
You must be signed in to change notification settings - Fork 1
Elasticsearch notes
In these examples, replace beta
with whichever index you're interested in.
Get statistics about an index
(Look at all > indexing > index_total
for the document count.)
GET /beta/_stats
Get count of documents
POST /beta/_count
Get a specific doc by ID
GET /beta/_doc/896f9132-8b1f-44cd-91f3-2423311668f2
Get all the docs. (A search with no criteria, at least. WARNING: Don't use on a real index. Postman will currently hang a large response.)
GET /beta/_search
Return specific fields
POST /beta/_search
{
"_source": {
"include": [ "id", "title" ],
"exclude": [ "content" , "file_base64" ]
}
}
The _source
property says what to return. You can either include
just the fields you want, or simply exclude
the big fields, as shown (it doesn't really make sense to do both).
By default the first ten hits are returned. To skip 100 hits and take the next 100 (paging):
{
...
"size": 100,
"from": 100
}
Search specific fields. Find the string "example" in the title
and content
fields.
{
"query": {
"multi_match" : {
"query" : "example",
"fields" : ["title", "content"]
}
},
...
}
Match on a single field
{
"query": {
"match" : {
"title" : "example"
}
},
"_source": {
"include": [ "id", "title" ]
}
}
Search on a date range
We add a timestamp_utc
field to every document. Use a range query to find all docs updated on or after a certain date:
{
"query": {
"range" : {
"timestamp_utc" : {
"gte" : "2019-04-09"
}
}
}
}