- 全局搜索
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);
推荐阅读
-
迪丽热巴|3月好剧扎堆,肖战、杨紫、迪丽热巴、任嘉伦,开启强势霸屏
-
|宇宙中可能存在宝石星球!高碳氧环境下满地都是钻石
-
共由说游戏|先抢物资才是关键,还有哪些吃鸡技巧?,和平精英:斜飞跳伞最快
-
伊一|女星伊一穿紧身衣健身!身上压180斤器械,男教练一旁全程保护
-
美国电影中,刚出狱的人、即将死刑的人,为何总想吸支烟这么长时间都戒不掉
-
生肖|7月10号开始这三生肖气运非常的旺,时来运转,富贵盈门
-
『五谷杂粮』五谷杂粮有预防慢性疾病高血压糖尿病的作用
-
-
-
[海南SEO]能过上幸福生活,还总能遇到幸运的三大生肖,下周运势旺
-
-
[佟丽娅]佟丽娅好有女人味,一袭黑色小短裙秀身材,“豆腐腿”好抢眼
-
[消费]咖啡馆撸猫、健身房“撸铁”,服务消费超过居民消费“半壁
-
晓枫微红|不许人间见白头,小乔初嫁又如何?,美人自古多薄命
-
-
猫爷看时尚宋妍霏显胖、蓝盈盈显瘦,袁姗姗中规中矩?,女明星最新机场look
-
勒布朗-詹姆斯|开门红!湖人三节打花热火,詹眉爆发合砍59分,巴特勒热巴伤退
-
张爱玲 迟暮 赏析-比美人迟暮,才华熄灭更让人心碎的是-
-
疫情|大洋电机:预计2020年半年度净利润7000万元~1亿元,同比下降63%~74%
-