- 全局搜索
GET /shops_index,goods_index/_search//多索引搜索用逗号隔开或者 /_all/_search、/_search{"query": {"multi_match": {"query": "口腔",// 如果查询字段 *口腔* 则fileds 必须["goods_title.keyword^10","goods_subtitle.keyword^7"]^1表示权重"fields": ["goods_title", "title"]}}"_source": ["goods_title","title"] //查询字段}
- match_all
{"query":{"match_all":{} //查询所有}}
- 分页查询
{"query": {"match_all":{} //查询所有},"from":0,"size":10}
- match_phrase
查询同一个字段中几个词,可以跳过其他词,slop表示可以跳过的最大词数
{"query": {"match_phrase": {"description": "He is","slop":100}}}
- term 单个条件查询
(不会分词,精确匹配)一句话解释: elasticsearch 里默认的IK分词器是会将每一个中文都进行了分词的切割,所以你直接想查一整个词,或者一整句话是无返回结果的 。查询不是中文的字符串能查不出来
{"query": {"term": {"category_id": "10052", // 能查出数据//"goods_title" : "体检", 查不出来因为中文分词了,除非就一个汉字}}}
- terms 多个关键字查询
"query": {"terms": {"channel_id": [102,101]}}
- match 条件查询
会分词,全文检索
{"query": {"match": {"goods_title": "体检"}}}{"query": {"match": {"goods_title": {"query": "体检","operator": "and" // or 表示只要有一个分词就可以查询出来,and 表示必须包含分出来的所有字段}}}}
- multi_match 多个字段检索
{"query": {"multi_match": {"query": "口腔","fields": ["goods_title","goods_subtitle"]}}}
- exits 检索字段存在
{"query": {"exists": {"field": "goods_title"}}}
- bool 检索
must :多个条件全部要满足;should:或者的意思,满足一个即可;must_not:除了满足所有条件剩下的数据
{"query": {"bool": {"must": [{"multi_match":{"query":"口腔","fields":["goods_title","goods_subtitle"]}},{"term":{"age":19}},{"terms": {"brand_name.keyword": ["白敬宇"] //类似in查询}}],"must_not":[{"terms": {"goods_id": [1,2,3]}}]}}}
- post_filter 对结果过滤
{"query": {"match": {"goods_title": "口腔"}},"post_filter": {"range": {"selling_price": {"gte": 1000,"lte": 1500}}}}
- sort 排序
{"query": {"match": {"goods_title": "口腔"}},"post_filter": {"range": {"selling_price": {"gte": 1000,"lte": 2000}}},"sort": [{"selling_price": {"order": "asc"}}],"_source": ["selling_price"]}
- 修改setting
注意:修改setting需要先关闭所以,然后再开启索引
$es->indices()->close(['index' => $index]);$params_setting = ['index' => $index,'body'=> ['settings' => ['analysis' => ['analyzer' => ['ik_pinyin_analyzer' => ['type'=> 'custom','tokenizer' => 'ik_max_word','filter'=> ["my_pinyin", "word_delimiter"],]],'filter'=> ["my_pinyin" => ["type"=> "pinyin","first letter" => "prefix","padding_char" => " "]]]]]];$es->indices()->putSettings($params_setting);$es->indices()->open(['index' => $index]);
- 修改mApping
PUT fit_goods_index/_mapping{"properties":{"search_title":{"type":"text"}}}// php代码$params = ['index' => $index,'body'=> ['_source'=> ['enabled' => true],'properties' => ['location'=> ['type'=> 'geo_point','ignore_malformed' => true],'completion' => ['type'=> 'completion','analyzer' => 'ik_pinyin_analyzer','fields'=> ["key" => ["type" => "keyword"],],"contexts" => [["type" => "category","name" => "plan_id"]]],]]];$es->indices()->putMapping($params);
推荐阅读
-
龙之队|iPhone12起售价4899元?网友:为收割华为高端用户吧
-
-
-
布拉德·皮特|希洛:出生就巅峰,遗传朱莉和皮特的超高颜值,16岁美出水
-
-
环球资讯快报|配96单元导弹垂发系统,火力仅次于055大驱,伊朗版濒海舰亮相
-
数码小小白 还在用4G网的iPhone11,为何如此火爆,5G时代来临
-
Intel|NUC 12发烧版迷你机用上Intel独立显卡:16TB+1TB 1.36万元
-
肝脏|肝病\救星\找到了,不是猪血,没事泡点,清理肝毒,肝越来越好
-
潮人|潮流 | 2Pac于服刑中所创作之诗词《4 What It’z Worth》正式曝光
-
-
刚买回来猫需要检查什么,刚买回来的小猫不吃东西怎么办
-
面试@当HR问你期望薪水多少?千万别先亮底牌,这样回答才显情商高
-
-
虎扑足球|未遵守防疫规定遭重罚!奥地利联赛领头羊被扣6分丢掉榜首
-
比尔盖茨|比尔盖茨决定离婚后被扒:每年都和前女友度假
-
震源深度|河北唐山市古冶区发生5.1级地震,震源深度10千米
-
明星照片|霍建华林心如与友人聚餐,3岁女儿正面照首曝光,长相甜美惹人爱
-
『呆妹儿』小团团和呆妹和好了?两人首次连线开黑,菜到无法直视
-