joelin109 / blog

0 stars 0 forks source link

Util: ElasticSearch - Basic DSL queries #27

Open joelin109 opened 3 years ago

joelin109 commented 3 years ago

ES的查询语言叫做DSL(结构化查询)

DSL(Domain Specific Language ), 以JSON的请求形式, 允许构建更复杂、强大的查询


match: where 'English' in language or 'Chinese' in language 分词查询, 对text类型字段,会对文本先进行分词进行查询


"query": { "match_phrase": { "language" : "English, Chinese" } } }

match_phrase: where language like '%english, chinese'


- 单词搜索与过滤(Term和Terms)

"query": { "term": { "language" : "english" } } }

Similar: where 'english' in language 精确查询,通常对keyword和有精确值的字段进行查询


- ④ 组合条件搜索与过滤(Bool)

"query": { "bool": {

  "must": [
    {    
      "match": {"language": "english, chinese"}
    },
    {
      "term": {"address": "shanghai"}
    },
    {
      "range": {"age": {"gte": 18,"lte": 40}}
    }
  ],

  "must_not": [
    {
      "term": { "name": "john"}
    }
  ]

}

}


- ⑤ 范围查询与过滤(range)

GET joe_dbase_index/_search { "query": { "range": { "age": { "gte": 18, "lte": 36 } } } }

where age >= 18 and age <=36


- ⑥ 存在和缺失过滤器(exists和missing)

- ⑦ 前匹配搜索与过滤(prefix)
joelin109 commented 2 years ago

https://www.jianshu.com/p/e589181b14db