vgrabovets
3/22/2017 - 8:22 PM

demo

demo

GET /

POST /my-index/my-type/1
{
  "body": "foo"
}

GET /my-index/my-type/1

GET /my-index/_search
{
  "query": {
    "match": {
      "body": "foo"
    }
  }
}

DELETE /my-index/my-type/1

PUT /library
{
  "settings": {
    "index.number_of_shards": 1,
    "index.number_of_replicas": 0
  }
}

POST /library/books/_bulk
{"index": {"_id": 1}}
{"title": "The quick brown fox", "price": 5, "colors": ["red", "green", "blue"]}
{"index": {"_id": 2}}
{"title": "The quick brown fox jumps over the lazy dog", "price": 15, "colors": ["yellow", "blue"]}
{"index": {"_id": 3}}
{"title": "The quick brown fox jumps over the quick dog", "price": 8, "colors": ["red", "blue"]}
{"index": {"_id": 4}}
{"title": "Brown fox brown dog", "price": 2, "colors": ["red", "black", "blue", "yellow"]}
{"index": {"_id": 5}}
{"title": "Lazy dog", "price": 9, "colors": ["red", "green", "blue"]}

GET /library/books/_search
{
  "query": {
    "match_phrase": {
      "title": "quick"
    }
  }
}

GET /library/books/_search
{
  "query": {
    "bool": {
      "must": [
        {
          "match": {
            "title": "quick"
          }
        },
        {
          "match_phrase": {
            "title": "lazy dog"
          }
        }
      ]
    }
  }
}

GET /library/books/_search
{
  "query": {
    "bool": {
      "must_not": [
        {
          "match": {
            "title": "lazy"
          }
        },
        {
          "match_phrase": {
            "title": "lazy dog"
          }
        }
      ]
    }
  }
}

GET /library/books/_search
{
  "query": {
    "bool": {
      "should": [
        {
          "match_phrase": {
            "title":  "quick dog"
          }
        },
        {
          "match_phrase": {
            "title": {
              "query": "lazy dog",
              "boost": 3
            }
          }
        }
      ]
    }
  }
}

GET /library/books/_search
{
  "query": {
    "bool": {
      "should": [
        {
          "match_phrase": {
            "title":  {
              "query": "quick dog",
              "boost": 2
            }
          }
        },
        {
          "match_phrase": {
            "title": {
              "query": "lazy dog"
            }
          }
        }
      ]
    }
  },
  "highlight": {
    "fields": {
      "title": {}
    }
  }
}

GET /library/books/_search
{
  "query": {
    "bool": {
      "must": [
        {
          "match": {
            "title": "dog"
          }
        }
      ],
      "filter": {
        "range": {
          "price": {
            "gte": 5,
            "lte": 10
          }
        }
      }
    }
  }
}

GET /library/books/_search
{
  "query": {
    "bool": {
      "filter": {
        "range": {
          "price": {
            "gt": 5
          }
        }
      }
    }
  }
}

GET /library/_analyze
{
  "tokenizer": "standard",
  "filter": ["lowercase", "unique"],
  "text": "BROWN FOX BROWN DOG"
}

GET /library/_analyze
{
  "analyzer": "standard",
  "text": "BROWN FOX BROWN DOG"
}

GET /library/_analyze
{
  "tokenizer": "standard",
  "filter": ["lowercase"],
  "text": "THE quick.brown_FOx Jumped! $19.95 @ 3.0"
}

GET /library/_analyze
{
  "tokenizer": "letter",
  "filter": ["lowercase"],
  "text": "THE quick.brown_FOx Jumped! $19.95 @ 3.0"
}

GET /library/_analyze
{
  "tokenizer": "standard",
  "text": "elastic@example.com website: https://www.elastic.co"
}

GET /library/_analyze
{
  "tokenizer": "uax_url_email",
  "text": "elastic@example.com website: https://www.elastic.co"
}

GET /library/_search
{
  "size": 0,
  "aggs": {
    "popular-colors": {
      "terms": {
        "field": "colors.keyword"
      }
    }
  }
}

GET /library/_search
{
  "query": {
    "match": {
      "title": "dog"
    }
  }, 
  "aggs": {
    "popular-colors": {
      "terms": {
        "field": "colors.keyword"
      }
    }
  }
}

GET /library/_search
{
  "size": 0,
  "aggs": {
    "price-statistics": {
      "stats": {
        "field": "price"
      }
    },
    "popular-colors": {
      "terms": {
        "field": "colors.keyword"
      },
      "aggs": {
        "avg-price-per-color": {
          "avg": {
            "field": "price"
          }
        }
      }
    }
  }
}

GET /library/books/1

POST /library/books/1
{
  "title": "The quick brown fox",
  "price": 10,
  "colors": ["red", "green", "blue"]
}

POST /library/books/1/_update
{
  "doc": {
    "title": "The quick fantastic fox"
  }
}

GET /library/_mapping