zoukankan      html  css  js  c++  java
  • elasticsearch查询

    1、REST Request URI

    2、REST Request Body
    1)查询设置
    1. curl -XPOST http://vm1:9200/customer/external/_search?pretty -d '{
    2. query: {match_all: {}},
    3. size: 5,
    4. from: 0,
    5. sort: {balance: {order: "desc"}},
    6. _source: ["balance", "account_number"]
    7. '
    query:设置查询条件
    size:返回的数据量
    from:数据从哪条开始,第一条是0
    sort:排序
    _source:返回哪些字段

    2)查询条件
    • match query
    match_all:所有数据
    match:等于或包含某些值的
    match_phrase:等于或包含某个值

    查询所有数据
    1. curl -XPOST http://vm1:9200/customer/external/_search?pretty -d '{query: {match_all: {}}}'
    查询account_number(数值类型)是20的数据
    1. curl -XPOST http://vm1:9200/customer/external/_search?pretty -d '
    2. {
    3. query: {match: {account_number: 20}}
    4. }'

    查询address包含mill的数据
    1. curl -XPOST http://vm1:9200/customer/external/_search?pretty -d '
    2. {
    3. query: {match: {address: "mill"}}
    4. }'

    查询address包含mill或lane的数据
    1. curl -XPOST http://vm1:9200/customer/external/_search?pretty -d '
    2. {
    3. query: {match: {address: "mill lane"}}
    4. }'

    查询address包含"mill lane"的数据,文本作为一个整体进行比较
    1. curl -XPOST http://vm1:9200/customer/external/_search?pretty -d '
    2. {
    3. query: {match_phrase: {address: "mill lane"}}
    4. }'

    • boolean query

    must:相当于and操作
    should:相当于or操作
    must_not:相当于非操作

    address包含mill并且包含lane
    1. curl -XPOST http://vm1:9200/customer/external/_search?pretty -d '
    2. {
    3. query: {bool: {must: [{match: {address: "mill"}}, {match: {address: "lane"}}]}}
    4. }'

    address包含mill或包含lane
    1. curl -XPOST http://vm1:9200/customer/external/_search?pretty -d '
    2. {
    3. query: {bool: {should: [{match: {address: "mill"}}, {match: {address: "lane"}}]}}
    4. }'

    address不包含mill并且不包含lane
    1. curl -XPOST http://vm1:9200/customer/external/_search?pretty -d '
    2. {
    3. query: {bool: {must_not: [{match: {address: "mill"}}, {match: {address: "lane"}}]}}
    4. }'

    多个条件组合
    1. curl -XPOST 'localhost:9200/bank/_search?pretty' -d '
    2. {
    3.   "query": {
    4.     "bool": {
    5.       "must": [
    6.         { "match": { "age": "40" } }
    7.       ],
    8.       "must_not": [
    9.         { "match": { "state": "ID" } }
    10.       ]
    11.     }
    12.   }
    13. }'
    filter query

    aggregation query
























  • 相关阅读:
    机器学习-数据可视化神器matplotlib学习之路(四)
    [AspNetCore]CookieAuthentication禁用自动跳转到登录页
    [AspNetCore3.1] 使用Serilog记录日志
    [排序算法二]选择排序
    [排序算法一]冒泡排序
    Ocelot 网关 和 consul 服务发现
    AspNetCore3.0 和 JWT
    在AspNetCore3.0中使用Autofac
    【ElasticSearch+NetCore 第二篇】Nest封装
    【ElasticSearch+NetCore 第一篇】在Windows上安装部署ElasticSearch和ElasticSearch-head
  • 原文地址:https://www.cnblogs.com/lishouguang/p/4560935.html
Copyright © 2011-2022 走看看