ElasticSearch filter query

Before learning inquiry, I was the old rules, prepare data

#Filter查询
#filter是不计算相关性的,同时可以cache.因此,filter速度要快于query.
POST /lib5/items/_bulk
{"index":{"_id": 1}}
{"price": 40,"itemID": "ID100123"}
{"index":{"_id": 2}}
{"price": 50,"itemID": "ID100124"}
{"index":{"_id": 3}}
{"price": 25,"itemID": "ID100124"}
{"index":{"_id": 4}}
{"price": 30,"itemID": "ID100125"}
{"index":{"_id":5}}
{"price": null, "itemID": "ID100127"}

 

 

Queries price (the price of 40 filter data) 40

Check Rates of 25 and 40

 note:

We post the request to add data I use the dynamic mapping, mapping automatically created, we can look mapping

Note: we saw itemID type text, and text is the default type of word, when the word will be "ID100123" uppercase letters converted to lowercase "id100123"

We will try to change the lowercase found to be ok as shown below:         

 

check sentence:

####2.8.1简单的过滤查询
#term
GET /lib5/items/_search
{ 
  "post_filter":{
    "term":{ "price":40}
  }
} 

#terms
GET /lib5/items/_search
{
  "post_filter":{
    "terms":{ "price": [25,40]}
  }  
}

GET /lib5/items/_search
{
  "post_filter":{
    "term": { "itemID": "ID100123"}
  } 
}
GET /lib5/items/_search
{
  "query": {
    "bool": {
      "filter": [{ "term": { "price": 40}}]
    }
  }
}

GET /lib5/items/_search
{
  "query": {
    "bool": {
      "filter": [{ 
        "terms": { "price": [25,40] }
      }]
    }
  }
}

GET /lib5/items/_search
{
  "query": {
    "bool": {
      "filter": [{
        "term": { "itemID":"5100123" }
      }]
    }
  }
}

 

Published 298 original articles · won praise 107 · Views 140,000 +

Guess you like

Origin blog.csdn.net/ywl470812087/article/details/105013351