1. 程式人生 > 其它 >Elasticsearch: filter => query

Elasticsearch: filter => query

 

put wares
{
  "settings":{
    "number_of_shards": 1,
    "number_of_replicas":0
  },
  "mappings":{
    "properties":{
      "id":{
        "type":"integer"
      },
      "title":{
        "type": "keyword"
      },
      "price":{
        "type":"double"
      },
      "create_at":{
        "type
":"date" }, "description":{ "type":"text", "analyzer": "ik_max_word" } } } } get _cat/indices?v get wares/_mapping delete orders # 手動指定_id post wares/_doc/1 { "id": 1, "title": "小浣熊", "price": 0.5, "create_at": "2022-11-02", "description": "小浣熊真好吃" } post wares
/_doc/2 { "id": 2, "title": "魚豆腐", "price": 4.8, "create_at": "2022-11-02", "description": "魚豆腐很不錯,真好吃rtyu uiop" } # 自動生成_id post wares/_doc { "id": 3, "title": "日本豆", "price": 1.8, "create_at": "2022-11-02", "description": "日本豆很不錯" } post wares/_doc { "id": 4, "title": "紅燒排骨魚翅",
"price": 7.8, "create_at": "2022-10-02", "description": "紅燒排骨魚翅, 這個菜很獨特" } post wares/_doc { "id": 4, "title": "紅燒排骨魚翅", "price": 7.8, "create_at": "2022-10-02", "description": "紅燒排骨魚翅, 這個菜很獨特,好吃好吃" } get valian/_search { "query":{ "term":{ "description": { "value": "好吃" } } } } get valian/_search { "query":{ "bool":{ "must": [ { "term":{ "description": {"value": "好吃"} } } ] } } } # filter term get valian/_search { "query":{ "bool":{ "must": [ { "match_all": {} } ], "filter": [ { "term":{ "description": {"value": ""} } } ] } } } # filter terms get valian/_search { "query":{ "bool":{ "must": [ { "match_all": {} } ], "filter": [ { "terms":{ "description": ["好吃","日本"] } } ] } } } # filter range get valian/_search { "query":{ "bool":{ "must": [ { "match_all": {} } ], "filter": [ { "range": { "price": { "gte": 0, "lte": 4 } } } ] } } } # filter exists get valian/_search { "query":{ "bool":{ "must": [ { "match_all": {} } ], "filter": [ { "exists": { "field": "price" } } ] } } } # filter ids get valian/_search { "query":{ "bool":{ "must": [ { "match_all": {} } ], "filter": [ { "ids":{ "values": [1,2] } } ] } } } get valian/_search { "query":{ "bool":{ "must": [ { "term":{ "description": {"value": "好吃"} } } ], "filter": [ { "term":{ "description": {"value": ""} } } ] } } }