- 全局搜索
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);
推荐阅读
-
「运势」5月3号运势如虹,财旺运旺,贵人如云,咸鱼翻身发大财的3生肖
-
「运输机」国外媒体称轰20为红色B2,准确消息称今年将首次飞行。军迷们蹲了三天三夜。
-
母亲把高考女儿送错考点当场痛哭|母亲把高考女儿送错考点当场痛哭 究竟怎么回事?
-
-
-
梦泪|梦泪和Fly多排,梦泪拿出马超,Fly拿出花木兰,这真是神仙组合!
-
隔年的橘子皮不就是“陈皮”,为啥能卖到5000一斤?专家说出实情
-
-
央视新闻客户端|阿根廷确诊病例超125万 首都已取消隔离管控
-
-
-
-
王岳伦亲手为李湘画画像,当成品出来的那一刻,这技术没搞错吧?
-
-
生肖▲下月开始,红鸾星动,前缘未了,和前任甜蜜牵手的四大生肖
-
-
-
开幕|“写不尽的世界”李名郎书法作品展,昨日在云栖小镇谷田美术馆开幕
-
梦见梨树是什么意思,好不好,代表什么 梦见梨树是什么意思周公解梦
-