美文网首页
URI Search 详解

URI Search 详解

作者: 7赢月 | 来源:发表于2020-04-12 15:34 被阅读0次

参数解释

示例:

GET /movies/_search?q=2012&df=title&sort=year:desc&from=0&size=10&timeout=1s
{
    "profile":"true"
}
  • q:置顶查询关键字 使用query string syntax
  • df:置查询字段,其中总置顶查询title中包含2012的结果
  • sort:用于排序 from和size用于分页
  • profile:可以查看查询是怎么运行的

接下来会详细介绍query string syntax

  • 指定字段和范查询
    q=title:2012置顶字段;
    q=2012泛查询
GET /movies/_search?q=2012
{
    "profile":"true"
}
image.png

我们可以看到查询结果中查询了所有字段

指定字段查询

GET /movies/_search?q=title:2012
{
    "profile":"true"
}
image.png

查询结果中只查询了title字段

  • term vs phrase
    其中的term和上面的
GET /movies/_search?q=title:2012
{
    "profile":"true"
}

这个就是使用的termQuery
phrase query:查询电影title中包含Beautiful AND Mind

GET /movies/_search?q=title:"Beautiful Mind"
{
    "profile":"true"
}
image.png
  • boolQuery AND OR NOT这三种语法都能用 不过必须大写 也可以使用 && || !
    查询title中包含Beautiful 或者 Mind 的电影
GET /movies/_search?q=title:(Beautiful Mind)
{
    "profile":"true"
}
image.png
  • 分组
    -- +标识must也就是必须包含
    -- -标识must not标识必须不包含
GET /movies/_search?q=title:(Beautiful +Mind)
{
    "profile":"true"
}
image.png
  • 通配符查询 不过这个查询可想而知的是查询效率很低:
    -- ?代表1个字符
    -- *代表0个或者多个字符
GET /movies/_search?q=title:b*
{
    "profile":"true"
}

查询title中包含b开头

  • 模糊匹配和近似查询
    -- 使用~1标识模糊匹配
    -- 使用“lord rings”~2标识匹配两个单词中间还能出现两个词
GET /movies/_search?q=title:beautifl~1
{
    "profile":"true"
}

beautifl~1 可匹配beautifly


image.png
GET /movies/_search?q=title:"Lord Rings"~2
{
    "profile":"true"
}

"Lord Rings"~2 匹配上了"Lord of the Rings


image.png

小结

本章介绍了URI Search 其中主要介绍了query string syntax的用法

引用

https://time.geekbang.org/course/detail/197-104956

相关文章

网友评论

      本文标题:URI Search 详解

      本文链接:https://www.haomeiwen.com/subject/qgavmhtx.html