Saturday, July 2, 2022

Elasticsearch Queries - Match, MatchPhrase, Term and Fuzzy Query


via IFTTT

curl -XDELETE "http://localhost:9200/shakespeare"

rm shakespeare.json

curl -O https://download.elastic.co/demos/kibana/gettingstarted/8.x/shakespeare.json

curl -XPUT "http://localhost:9200/shakespeare" -H 'Content-Type: application/json' -d'
{
  "mappings": {
    "properties": {
    "speaker": {"type": "keyword"},
    "play_name": {"type": "keyword"},
    "line_id": {"type": "integer"},
    "speech_number": {"type": "integer"}
    }
  }
}'

curl -XGET "http://localhost:9200/shakespeare?pretty"

curl -H 'Content-Type: application/x-ndjson' -XPOST 'http://localhost:9200/shakespeare/_bulk?pretty' --data-binary @shakespeare.json

GET _cat/indices?v

GET /shakespeare

GET /shakespeare/_count

GET /shakespeare/_search?from=200&size=10

GET /shakespeare/_doc/205

GET /shakespeare/_mapping

GET /shakespeare/_search
{
  "query": {
    "match": {
      "text_entry": "Ill be damned for never a kings son in"
    }
  }
}

GET /shakespeare/_search
{
  "query": {
    "match_phrase": {
      "text_entry": "Ill be damned for never a kings son in"
    }
  }
}

GET /shakespeare/_search
{
  "query": {
    "term": {
      "text_entry": "king"
    }
  }
}


GET /shakespeare/_search
{
  "query": {
    "term": {
      "line_id": 206
    }
  }
}

GET /shakespeare/_search
{
  "query": {
    "term": {
      "line_id": 2067
    }
  }
}


GET /shakespeare/_search
{
  "query": {
    "fuzzy": {
      "play_name": {
        "value": "Henri I",
        "fuzziness": "AUTO"
      }
    }
  }
}


GET /shakespeare/_search
{
  "query": {
    "fuzzy": {
      "play_name": {
        "value": "Henri I",
        "fuzziness": "9"
      }
    }
  }
}



No comments:

Post a Comment

Note: Only a member of this blog may post a comment.