多索引多type搜索

分页搜索

每页5条 查询一到3页数据

第一页:http://127.0.0.1:9200/blogs2/product/_search?size=5&from=0

第二页:http://127.0.0.1:9200/blogs2/product/_search?size=5&from=5

第三页:http://127.0.0.1:9200/blogs2/product/_search?size=5&from=10

size参数为每页显示数量 from为跳过前面数量

搜索文档的一部分

或者通过指定排除属性和包含属性 支持匹配

http://localhost:9200/twitter/tweet/1?_source_include=*.id&_source_exclude=entities

搜索多个索引(type)文档

参数

{
"docs":[{
"_index":"blogs",
"_type":"product",
"_id":"1"
},{
"_index":"blogs2",
"_type":"product",
"_id":"2"
}]
}

结果

{
"docs": [
{
"_index": "blogs",
"_type": "product",
"_id": "1",
"_version": 13,
"_seq_no": 10,
"_primary_term": 1,
"found": true,
"_source": {
"productName": "测试修改",
"price": 11,
"remark": "不错的床垫",
"tags": [
"家具",
"床垫",
"棉花",
null
],
"videw": 1
}
},
{
"_index": "blogs2",
"_type": "product",
"_id": "2",
"_version": 1,
"_seq_no": 0,
"_primary_term": 1,
"found": true,
"_source": {
"productName": "法瑞思 天然椰棕床垫棕垫硬床垫定做 薄乳胶棕榈榻榻米床垫定制折叠1.2/1.5/1.8",
"price": 10,
"remark": "不错的床垫",
"tags": [
"家具",
"床垫",
"棉花"
]
}
}
]
}

如果index相同type不同

简易搜索

查询产品名字包含沙发同时品牌id为1的产品信息

or搜索?

文档是and搜索我测试时or搜索

http://127.0.0.1:9200/blogs2/product/_search?q=productName:大幅度 +price:10 如果一个字段多只查询 http://127.0.0.1:9200/blogs2/product/_search?q=productName:(大幅度 床垫) +price:10

所有字段中查询

查询所有字段里面包含床垫的文档

http://127.0.0.1:9200/blogs2/product/_search?q=测试

ES会将文档里面的所有值都拼接成一个串来查找

结构化查询DSL

term过滤

主要用于精确匹配 比如年龄  bool

{
"query":{
"term":{
"price":12
}
}
}

terms过滤

跟term相同 terms支持多值搜索  下面会搜索出单价为12和13的搜索出来

{
"query":{
"terms":{
"price":[12,13]
}
}
}

range过滤

{
"query": {
"range": {
"price": {
"gt": 10
}
}
}
}

将会查出价格大于10的  gt大于lt小于 gte大于等于 lte小于等于

大于等于小余等于

{
"query": {
"range": {
"price": {
"gt": 10,
"lt":13
}
}
}
}

exist

非空判断

{
"query": {
"missing": {
"field":"price"
}
}
}

字段不存在或为空判断

{
"query": {
"bool": {
"must_not": {
"exists": {
"field": "price"
}
}
}
}
}

bool过滤

合并多个查询条件的bool值

must:多个条件完全匹配相当于and

must_not 多个条件取想法 相当于<>

should: 至少有一个条件匹配相当于or

如下面例子

{
"query": {
"bool": {
"must":[
{"term":{"price":10}},
{"term":{"orgId":1}}
],
"numst_not":{
"term":{"id":1}
},
"should":[
{"term":{"id":10}},
{"term":{"id":20}}
]
}
}
}

(price=10 and orgId=1) and (id<>1) and (id=10 or id=20)

match_all

空查询

{
"query": {
"match_all":{}
}
}

match

在搜索确定值类型字段 将会按照完全匹配。如果是full text则是采用分词

{
"query": {
"match":{"price":10}
}
}

mult_match

与match相同 只是允许同时搜索多个字段

{
"query": {
"multi_match": {
"query": "不错的",
"fields": [
"productName","remark"
],
"operator": "AND"//OR AND
}
}
}

filter

filter将不进行_score打分 性能会高一点

{
"query": {
"bool": {
"must": {
"match": {
"productName": "床垫"
}
},
"filter": {
"match": {
"remark": "床垫"
} }
}
}
}

验证查询

验证一个查询是否有效

查询搜索分词索引情况

http://127.0.0.1:9200/blogs2/product/_validate/query?explain

查询权重分计算

get http://127.0.0.1:9200/index/type/id/_explain

body

{
"query":{
"match":{
"productName":"jw"
}
}
}

返回结果

{
"_index": "test",
"_type": "doc",
"_id": "560_406",
"matched": true,
"explanation": {
"value": 5.3691883,
"description": "sum of:",
"details": [
{
"value": 2.6373672,
"description": "weight(Synonym(productName:j productName:jw) in 0) [PerFieldSimilarity], result of:",
"details": [
{
"value": 2.6373672,
"description": "score(doc=0,freq=1.0 = termFreq=1.0\n), product of:",
"details": [
{
"value": 2.0502589,
"description": "idf, computed as log(1 + (docCount - docFreq + 0.5) / (docFreq + 0.5)) from:",
"details": [
{
"value": 56,
"description": "docFreq",
"details": []
},
{
"value": 438,
"description": "docCount",
"details": []
}
]
},
{
"value": 1.2863581,
"description": "tfNorm, computed as (freq * (k1 + 1)) / (freq + k1 * (1 - b + b * fieldLength / avgFieldLength)) from:",
"details": [
{
"value": 1,
"description": "termFreq=1.0",
"details": []
},
{
"value": 1.2,
"description": "parameter k1",
"details": []
},
{
"value": 0.75,
"description": "parameter b",
"details": []
},
{
"value": 32.90639,
"description": "avgFieldLength",
"details": []
},
{
"value": 15,
"description": "fieldLength",
"details": []
}
]
}
]
}
]
},
{
"value": 2.731821,
"description": "weight(productName:w in 0) [PerFieldSimilarity], result of:",
"details": [
{
"value": 2.731821,
"description": "score(doc=0,freq=1.0 = termFreq=1.0\n), product of:",
"details": [
{
"value": 2.1236863,
"description": "idf, computed as log(1 + (docCount - docFreq + 0.5) / (docFreq + 0.5)) from:",
"details": [
{
"value": 52,
"description": "docFreq",
"details": []
},
{
"value": 438,
"description": "docCount",
"details": []
}
]
},
{
"value": 1.2863581,
"description": "tfNorm, computed as (freq * (k1 + 1)) / (freq + k1 * (1 - b + b * fieldLength / avgFieldLength)) from:",
"details": [
{
"value": 1,
"description": "termFreq=1.0",
"details": []
},
{
"value": 1.2,
"description": "parameter k1",
"details": []
},
{
"value": 0.75,
"description": "parameter b",
"details": []
},
{
"value": 32.90639,
"description": "avgFieldLength",
"details": []
},
{
"value": 15,
"description": "fieldLength",
"details": []
}
]
}
]
}
]
}
]
}
}

查询explain分析器

http://127.0.0.1:9200/index/_search?_source

{
"profile":true,
"query":{
"match":{
"productName":"来啦"
}
}
}

count查询

通过url设置?_source=false 不返回_source 或者 get /index/type/_count

elasticsearch 权威指南搜索阅读笔记(四)的更多相关文章

  1. elasticsearch 权威指南入门阅读笔记(一)

    相关文档 esapi:https://es.xiaoleilu.com/010_Intro/10_Installing_ES.html     https://esdoc.bbossgroups.co ...

  2. elasticsearch 权威指南聚合阅读笔记(七)

    count(1) select clssId,count(1) from student group by  classId { "size":0, "aggs" ...

  3. elasticsearch 权威指南排序阅读笔记(六)

    默认排序 默认查询是通过_source 准确性权重来排序 字段排序 { "query":{ "match":{ "productName": ...

  4. 《Elasticsearch 权威指南》阅读笔记

    书籍地址 https://www.elastic.co/guide/cn/elasticsearch/guide/current/languages.html

  5. 《javascript权威指南》阅读笔记 1

    3.1-3.5 3.1 数字 3.1首先声明了在JS中的数字是不区分整数值和浮点数值的.其次给出了js浮点类型表示的范围:最大值是±1.7976931348623157×10^308,最小值±5×10 ...

  6. 《HTTP权威指南》--阅读笔记(二)

    URL的三部分: 1,方案 scheme 2,服务器位置 3,资源路径 URL语法: <scheme>://<user>:<password>@<host&g ...

  7. 《HTTP权威指南》--阅读笔记(一)

    HTTP: HyperText Transfer Protocol 测试站点:http://www.joes-hardware.com URI包括URL和URN URI: Uniform Resour ...

  8. 《javascript权威指南》读书笔记——第一篇

    <javascript权威指南>读书笔记——第一篇 金刚 javascript js javascript权威指南 由于最近想系统学习下javascript,所以开始在kindle上看这本 ...

  9. 《Kafka权威指南》读书笔记-操作系统调优篇

    <Kafka权威指南>读书笔记-操作系统调优篇 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 大部分Linux发行版默认的内核调优参数配置已经能够满足大多数应用程序的运 ...

随机推荐

  1. 64位oracle数据库用32位plsql developer无法连接问题(无法载入oci.dll)

    在64位操作系统下安装oracle数据库,新下载了64位数据库(假设是32位数据库安装在64位的操作系统上,无论是client还是server端.都不要去选择C:\Program Files (x86 ...

  2. luogu1357 花园 状态压缩 矩阵快速幂

    题目大意 小L有一座环形花园,沿花园的顺时针方向,他把各个花圃编号为1~N(2<=N<=10^15).他的环形花园每天都会换一个新花样,但他的花园都不外乎一个规则,任意相邻M(2<= ...

  3. oc59--匿名分类

    // // main.m // 匿名分类(延展) // 可以为某个类扩展私有的成员变量和方法,写在.m文件中, // 分类不可以扩展属性,分类有名字,匿名分类没有名字. #import <Fou ...

  4. 2017 Multi-University Training Contest - Team 2 &hdu 6055 Regular polygon

    Regular polygon Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)T ...

  5. 【JLOI 2014】 松鼠的新家

    [题目链接] https://www.lydsy.com/JudgeOnline/problem.php?id=3631 [算法] 树上差分 [代码] #include<bits/stdc++. ...

  6. 音频格式opus

    人耳能听到自然界的声音是20HZ-20KHZ,一般高保真音质采样率只有达到最高采样率的2倍以上即可,平时电话采样率8KHZ,CD音质的采样率44.1KHZ. IBM 的Watson的音频转文字接口支持 ...

  7. openStack 主机流量计运行状态 随笔记录

    root@ruiy-controller:~# ifconfigeth0      Link encap:Ethernet  HWaddr 0c:c4:7a:0d:97:2c          ine ...

  8. UIDynamicBehavior的简单使用:接球小游戏

    一.概念扩充: 1.在开发中,我们可以使用UIKit中提供的仿真行为,实现与现实生活中类似的物理仿真动画,UIKit动力学最大的特点是将现实世界动力驱动的动画引入了UIKit,比如重力,铰链连接,碰撞 ...

  9. codevs1253 超级市场(dp)

    1253 超级市场  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 钻石 Diamond       题目描述 Description 某人喜欢按照自己的规则去市场买菜,他每天 ...

  10. JavaScript学习杂记

    1.DOM层级:document(document) --> doctype,documentElement(html) --> head,body(body). 2.offset, cl ...