首页 > 其他分享 >Query DSL

Query DSL

时间:2024-03-06 09:04:41浏览次数:16  
标签:index name db source DSL score Query es

match_all

匹配所有文档,默认分页查询,只显示后十条数据,如下所示在索引中的数据有11条数据,在进行match_all查询时只返回了十条数据.

    "total": {
      "value": 11,
      "relation": "eq"
    }
GET /es_db/_search
{
  "query": {
    "match_all": {
    }
  }
}

{
  "took": 4,
  "timed_out": false,
  "_shards": {
    "total": 1,
    "successful": 1,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": {
      "value": 11,
      "relation": "eq"
    },
    "max_score": 1,
    "hits": [
      {
        "_index": "es_db",
        "_id": "10",
        "_score": 1,
        "_source": {
          "name": "开人员",
          "sex": 1,
          "age": 32,
          "address": "武汉东湖高新区未来智汇城",
          "remark": "golang developer"
        }
      },
      {
        "_index": "es_db",
        "_id": "8",
        "_score": 1,
        "_source": {
          "name": "张星",
          "sex": 1,
          "age": 32,
          "address": "武汉东湖高新区未来智汇城",
          "remark": "golang developer"
        }
      },
      {
        "_index": "es_db",
        "_id": "6",
        "_score": 1,
        "_source": {
          "name": "赵虎",
          "sex": 1,
          "age": 32,
          "address": "长沙麓谷兴工国际产业园",
          "remark": "java architect"
        }
      },
      {
        "_index": "es_db",
        "_id": "5",
        "_score": 1,
        "_source": {
          "name": "张龙",
          "sex": 0,
          "age": 19,
          "address": "长沙麓谷企业广场",
          "remark": "java architect assistant"
        }
      },
      {
        "_index": "es_db",
        "_id": "7",
        "_score": 1,
        "_source": {
          "name": "李虎",
          "sex": 1,
          "age": 32,
          "address": "广州番禺节能科技园",
          "remark": "java architect"
        }
      },
      {
        "_index": "es_db",
        "_id": "3",
        "_score": 1,
        "_source": {
          "name": "王五",
          "sex": 0,
          "age": 26,
          "address": "广州白云山公园",
          "remark": "php developer"
        }
      },
      {
        "_index": "es_db",
        "_id": "1",
        "_score": 1,
        "_source": {
          "name": "张三",
          "sex": 1,
          "age": 25,
          "address": "广州天河公园",
          "remark": "java developer"
        }
      },
      {
        "_index": "es_db",
        "_id": "2",
        "_score": 1,
        "_source": {
          "name": "李四",
          "sex": 1,
          "age": 28,
          "address": "广州荔湾大厦",
          "remark": "java assistant"
        }
      },
      {
        "_index": "es_db",
        "_id": "4",
        "_score": 1,
        "_source": {
          "name": "赵六",
          "sex": 0,
          "age": 22,
          "address": "长沙橘子洲",
          "remark": "python assistant"
        }
      },
      {
        "_index": "es_db",
        "_id": "11",
        "_score": 1,
        "_source": {
          "name": "企业人员",
          "sex": 1,
          "age": 32,
          "address": "武汉东湖高新区未来智汇城",
          "remark": "golang developer"
        }
      }
    ]
  }
}

如果想要指定分页查询可以使用from和size参数,如下所示,from表示从第几条记录开始分页,size表示每页展示几条数据

GET /es_db/_search
{
  "query": {
    "match_all": {
      
    }
  },
    "from": 0,
    "size": 11
}


{
  "took": 6,
  "timed_out": false,
  "_shards": {
    "total": 1,
    "successful": 1,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": {
      "value": 11,
      "relation": "eq"
    },
    "max_score": 1,
    "hits": [
      {
        "_index": "es_db",
        "_id": "10",
        "_score": 1,
        "_source": {
          "name": "开人员",
          "sex": 1,
          "age": 32,
          "address": "武汉东湖高新区未来智汇城",
          "remark": "golang developer"
        }
      },
      {
        "_index": "es_db",
        "_id": "8",
        "_score": 1,
        "_source": {
          "name": "张星",
          "sex": 1,
          "age": 32,
          "address": "武汉东湖高新区未来智汇城",
          "remark": "golang developer"
        }
      },
      {
        "_index": "es_db",
        "_id": "6",
        "_score": 1,
        "_source": {
          "name": "赵虎",
          "sex": 1,
          "age": 32,
          "address": "长沙麓谷兴工国际产业园",
          "remark": "java architect"
        }
      },
      {
        "_index": "es_db",
        "_id": "5",
        "_score": 1,
        "_source": {
          "name": "张龙",
          "sex": 0,
          "age": 19,
          "address": "长沙麓谷企业广场",
          "remark": "java architect assistant"
        }
      },
      {
        "_index": "es_db",
        "_id": "7",
        "_score": 1,
        "_source": {
          "name": "李虎",
          "sex": 1,
          "age": 32,
          "address": "广州番禺节能科技园",
          "remark": "java architect"
        }
      },
      {
        "_index": "es_db",
        "_id": "3",
        "_score": 1,
        "_source": {
          "name": "王五",
          "sex": 0,
          "age": 26,
          "address": "广州白云山公园",
          "remark": "php developer"
        }
      },
      {
        "_index": "es_db",
        "_id": "1",
        "_score": 1,
        "_source": {
          "name": "张三",
          "sex": 1,
          "age": 25,
          "address": "广州天河公园",
          "remark": "java developer"
        }
      },
      {
        "_index": "es_db",
        "_id": "2",
        "_score": 1,
        "_source": {
          "name": "李四",
          "sex": 1,
          "age": 28,
          "address": "广州荔湾大厦",
          "remark": "java assistant"
        }
      },
      {
        "_index": "es_db",
        "_id": "4",
        "_score": 1,
        "_source": {
          "name": "赵六",
          "sex": 0,
          "age": 22,
          "address": "长沙橘子洲",
          "remark": "python assistant"
        }
      },
      {
        "_index": "es_db",
        "_id": "11",
        "_score": 1,
        "_source": {
          "name": "企业人员",
          "sex": 1,
          "age": 32,
          "address": "武汉东湖高新区未来智汇城",
          "remark": "golang developer"
        }
      },
      {
        "_index": "es_db",
        "_id": "9",
        "_score": 1,
        "_source": {
          "name": "泥马勒戈壁",
          "sex": 1,
          "age": 32,
          "address": "武汉东湖高新区未来智汇城",
          "remark": "golang developer"
        }
      }
    ]
  }
}

_source

返回字段限制,如下所示,如果只想显示name和index字段可以以以下方式进行查询

GET /es_db/_search
{
  "_source": ["name", "age"], 
  "query": {
    "match_all": {
      
    }
  }
}

查询结果
{
  "took": 5,
  "timed_out": false,
  "_shards": {
    "total": 1,
    "successful": 1,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": {
      "value": 11,
      "relation": "eq"
    },
    "max_score": 1,
    "hits": [
      {
        "_index": "es_db",
        "_id": "10",
        "_score": 1,
        "_source": {
          "name": "开人员",
          "age": 32
        }
      },
      {
        "_index": "es_db",
        "_id": "8",
        "_score": 1,
        "_source": {
          "name": "张星",
          "age": 32
        }
      },
      {
        "_index": "es_db",
        "_id": "6",
        "_score": 1,
        "_source": {
          "name": "赵虎",
          "age": 32
        }
      },
      {
        "_index": "es_db",
        "_id": "5",
        "_score": 1,
        "_source": {
          "name": "张龙",
          "age": 19
        }
      },
      {
        "_index": "es_db",
        "_id": "7",
        "_score": 1,
        "_source": {
          "name": "李虎",
          "age": 32
        }
      },
      {
        "_index": "es_db",
        "_id": "3",
        "_score": 1,
        "_source": {
          "name": "王五",
          "age": 26
        }
      },
      {
        "_index": "es_db",
        "_id": "1",
        "_score": 1,
        "_source": {
          "name": "张三",
          "age": 25
        }
      },
      {
        "_index": "es_db",
        "_id": "2",
        "_score": 1,
        "_source": {
          "name": "李四",
          "age": 28
        }
      },
      {
        "_index": "es_db",
        "_id": "4",
        "_score": 1,
        "_source": {
          "name": "赵六",
          "age": 22
        }
      },
      {
        "_index": "es_db",
        "_id": "11",
        "_score": 1,
        "_source": {
          "name": "企业人员",
          "age": 32
        }
      }
    ]
  }
}

标签:index,name,db,source,DSL,score,Query,es
From: https://www.cnblogs.com/lyraHeartstrings/p/18055715

相关文章

  • AT_abc331_f [ABC331F] Palindrome Query 题解
    分析线段树。每个节点维护两个值:$s[l\dotsr]$和$s[r\dotsl]$。判断字串是否是回文直接就是询问的答案维护出来的两个值是否相同。首先想到用线段树暴力维护。第一个值很显然是两个儿子的第一个值加起来,第二个值是反着加起来。得到很酷的代码:ilvoidup(intnow){ tr[now......
  • AT_abc287_g [ABC287G] Balance Update Query 题解
    分析一眼分块。用值域分块来维护。先把所有的值离散化,使得至于不大于$n+q$。统计一下每个值的数量,每个块包含值的数量,每个块的价值和。修改值的时候先把原来值的数量,块包含的数量,块的价值剪掉被修改值的贡献,然后在新的值上面更新。修改数量直接改数量的变化贡献即可。找前$x$......
  • AT_abc287_g [ABC287G] Balance Update Query 题解2
    分析权值线段树。给每个节点赋一个值$val$和$a_i=val$的$b_i$之和。修改$a_x$的时候先将$a_x$的出现次数在树上剪掉$b_x$,再在$y$上面加上;修改$b_x$的时候直接加上变化量$y-b_x$。由于我们是要取前$x$大的$a_i$之和,在询问的时候有限考虑右儿子,然后在是当前......
  • jQuery UI简单的讲解
    原文链接:https://blog.csdn.net/omygodvv/article/details/134469683我们先进入一下问答时间,你都知道多少呢?(1)什么是jQueryUI呢?解答:jQueryUI是以jQuery为基础的开源JavaScript网页用户界面代码库。包含底层用户交互、动画、特效和可更换主题的可视控件。我们可以直接用......
  • 别再低效筛选数据了!试试pandas query函数
    数据过滤在数据分析过程中具有极其重要的地位,因为在真实世界的数据集中,往往存在重复、缺失或异常的数据。pandas提供的数据过滤功能可以帮助我们轻松地识别和处理这些问题数据,从而确保数据的质量和准确性。今天介绍的query函数,为我们提供了强大灵活的数据过滤方式,有助于从复杂的......
  • jQuery弹出窗口
    </html><!DOCTYPEHTMLPUBLIC"-//W3C//DTDXHTML1.0Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><htmlxmlns="http://www.w3.org/1999/xhtml"><head><metahttp-equiv=......
  • jquery ui和easyui的区别是什么?
    EasyUI是某公司开发的一套对私免费,对公收费的UI库,基于GNU开源协议,不过只有付费了才能买到他们的源代码。是目前枯人接触过最优秀的一款基于jQuery的UI库,整体打包后不到300k,几乎包含所有的常用组件。jqueryui和easyui的区别jqueryui是jQuery插件,是由jQuery官方维护的UI方向的插件;e......
  • 实现一个链式调用的query方法
    提供了一个数组结构的data,要求实现一个query方法,返回一个新的数组,query方法内部有过滤、排序、分组等操作,并且支持链式调用,调用最终的execute方法返回结果你可以按照以下步骤实现这个query方法:定义一个数组结构的data,例如:constdata=[{id:1,name:'Ali......
  • Balance Update Query
    link省选前写点简单题攒rp。显然每次选择,我们应该将所有物品从大到小排序,每次选择最大的\(x\)个。也就是每次要求前\(x\)大的数的和,随手写个平衡树可以做到这一操作,但是我不会,这里选择权值线段树来存贮每个数的个数,用线段树上二分解决前\(x\)大的数的和。注意离散化和......
  • 【3.0】前端基础jQuery之进阶
    【一】操作标签【1】操作类(1)JS版本[1]classList.add()方法用于向元素添加一个或多个类名。如果指定的类名已存在,则不会添加。element.classList.add("class1","class2");[2]classList.remove()方法用于从元素移除一个或多个类名。如果指定的类名不存在,则不会......