03 Elasticsearch operations
Creating and index: PUT /index_name
Define a mapping:
PUT /my_index/_mapping
{
"properties": {
"<field_name>": {
"type": "text"
}
}
}
Retrieve a document using its _id: GET /nyc-restourants/_doc/xxxxxxxxxx
Search
Match:
GET /nyc-restourants/_search
{
"query": {
"match": {
"<field>": <value>
}
}
}
Boolean:
GET /nyc-restourants/_search
{
"query": {
"bool": {
"must": [{}],
"must_not": [{}],
"should": [{}]
}
}
}
Filters
- Exact match
- For fields that are not analyzed
- No relevance
- The filter is either satisfied or not
- Cacheable
GET /nyc-restourants/_search
{
"query": {
"bool": {
"filter": {
"term": {
"<field>": <value>
}
}
}
}
}
GET /nyc-restourants/_search
{
"query": {
"bool": {
"filter": {
"prefix": {
"<field>": <value>
}
}
}
}
}
Count
GET /nyc-restourants/_count
{
"query": {
"match": {
"<field>": <value>
}
}
}
Aggregations
GET /nyc-restourants/_search
{
"size": 0,
"aggs": {
"score_group": {
"term": {
"field": "<field_name>"
}
}
}
}
No Comments