多索引多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. 安卓Recovery模式该怎么用?【转】

    本文转载自:http://android.baike.com/article-109914.html 安卓系统出了名的刷机刷机再刷机,说起刷机就不能不谈Recovery模式,这项刷机过程中最重要的一到 ...

  2. ASP.NET通用权限系统快速开发框架

    系统在线演示地址: http://120.90.2.126:8051 登录账户:system,密码:system### DEMO下载地址: http://download.csdn.net/detai ...

  3. poj 1741(树的点分治)

    Tree Give a tree with n vertices,each edge has a length(positive integer less than 1001). Define dis ...

  4. bzoj 1053 [ HAOI 2007 ] 反素数ant ——暴搜

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1053 试图打表找规律,但无果... 看TJ了,暴搜: 注意参数 w 是 long long. ...

  5. C语言程序创建文件

    #include <stdio.h>#include <stdlib.h>int main() { FILE *fp;if((fp=fopen("g:\\a.txt& ...

  6. SiteMesh3使用实例和详解

    一.SiteMesh介绍 SiteMesh是一个网页布局和修饰的框架,利用它可以将网页的内容和页面结构分离,以达到页面结构共享的目的.[来自百度百科] 通俗的理解就是,SiteMesh把页面中变化的和 ...

  7. [Apple开发者帐户帮助]二、管理你的团队(7)管理服务器帐户

    如果在配置机器人以在多个设备上运行应用程序时向团队添加服务器,允许Xcode Server为您管理签名,或者配置机器人以创建iOS App文件,则服务器可以访问您的资产并显示在您的开发人员帐户 您可以 ...

  8. ccf 201803-4 棋局评估 (对抗搜索)

    棋局评估 问题描述 Alice和Bob正在玩井字棋游戏. 井字棋游戏的规则很简单:两人轮流往3*3的棋盘中放棋子,Alice放的是“X”,Bob放的是“O”,Alice执先.当同一种棋子占据一行.一列 ...

  9. Activity生命周期(待整理)

    1. 定义 有一些方法共同定义生命周期,如下图示:(图片来自于官网文档) 2. onStart()——在Activity即将对用户可见之前调用 (1)Activity启动动画.二维动画在onStart ...

  10. logical vs physical address

    Logical vs physical address  1) An address generated by the CPU is a logical address. Whereas, an ad ...