- 全局搜索
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);
推荐阅读
-
家里阳台必养此款花卉,耐寒易打理,有着非常别致的韵味
-
今年26,学过街舞,还会唱歌,有点签约经纪公司的想法,北京还是上海更适合
-
-
『习惯』推行分餐制 做餐桌文明的倡行者——访中国饭店协会负责人
-
英特尔|Intel 11代酷睿正式发布:你能想到的 全变了
-
邱耀乐发声明回应炎亚纶,强调这不是无足轻重的情感纠纷
-
杜兰特什么时候能复出(杜兰特开始训练,复出时间确定了)
-
-
业务|江西邮储银行:以管理进阶、能力提升打响打好打赢公司业务收官之战
-
-
火爆新闻监考拦着不让进,场内考生喊:才9点29,笑话:我迟到31分钟
-
-
『活色有生香』美国高盛集团和SETL区块链公司展开合作
-
松鼠军评|局座称性质完全变了,互相驱逐外交官!大量先进战机部署对峙前线
-
-
张丰毅|刑侦剧《卧底警花》要火!张丰毅、张志坚强强联手,众星云集
-
移动互联网:app如何制作?3种不同app制作方法
-
-
-
国际米兰|即将官宣!国米3500万购新星,皮尔洛遭重创,孔蒂还要英超巨星