Elastic search

elastic search query

leaf query
match
term
range

compound query

---
match query
GET /_search
{
"query" : {
"match" :{
"message" : "this is a test"
}
}
}

note: message is field
match accepts text/numeric/dates
operator : or, and

anaylizer: field explicit mapping adefinition or default search analyzer

lenient: true -> ignore data type mismatch exception
fuzziness
===
term
exact term specified in the inverted index

POST _search
{
"query" : {
"term" : {
"user" : "Kimchy"
}
}
}

boot -> parameter, to give this term query a higher relevance score than another query

GET _search
{
"query" : {
"bool": {
"should": [
{
"term" : {
"status" : {
"value": "urgent",
"boost" : 2.0
}
}
},
{
"term" : {
"status" : "normal"
}
}
]
}
}
}

default, boost : 1.0
---
Range query
TermRange ->for string fields
NumericRangeQuery ->numeric/data
paramters: gt, gte, lt, lte
---
GET _search
{

"query" :{
"range":{
"age": {
"gte": 10,
"lte" : 20,
"boost": 2.0
}
}
}
}
--
range on date fields
GET _search
{
"query" : {
"range": {
"date": {
"gte": "now-1d/d",
"lt": "now"
}
}
}
}
---
date math
date format

"range" :{
"born": {
"gte": "01/01/2012",
"lte": "2013",
"format": "dd/MM/yyyy||yyyy"
}
}
---
"time_zone": "+01:00"
---
bool query
 must : match, add score
 filter: match, no score added
---
filter context
query context
miniumum_should_match
---
must_not
---
match vs should vs filter

constant_score
match_all
---
named queries
_name, top level definition
---
PUT my_index
{
  "mappings": {
    "doc": {
      "properties": {
        "title":    { "type": "text"  },
        "name":     { "type": "text"  },
        "age":      { "type": "integer" }, 
        "created":  {
          "type":   "date",
          "format": "strict_date_optional_time||epoch_millis"
        }
      }
    }
  }
}

No comments:

Post a Comment