curl命令

-XGET一种请求方法

-d 标识以post形式传入参数 ,写在请求正文里面

?pretty=true 以格式的形式显示结果

curl -XGET http://localhost:9200/_cluster/health?pretty --查询elasticsearch的健康信息
curl -XGET http://localhost:9200/ --查询实例的相关信息
curl -XGET http://localhost:9200/_cluster/nodes/ --得到集群中节点的相关信息
curl -XPOST http://localhost:9200/_cluster/nodes/_shutdown --关闭整个集群
curl -XPOST http://localhost:9200/_cluster/nodes/aaaa/_shutdown --关闭集群中指定节点
curl -XPOST http://localhost:9200/lishuai --创建名为lishuai的索引
curl -XDELETE http://localhost:9200/lishuai --删除名为lishuai的索引

curl -XGET  'Elasticsearch基本命令http://10.10.110.2:19200/benlaitest/_search?pretty=true' -d '{"query":{"multi_match":{"query":"法国","fields":["firstname","lastname"]}}}'   --查询数据(匹配firstname和lastname)

curl http://10.10.110.160:9200/benlaitest/_analyze?analyzer=standard -d 我爱你中国

postman执行请求API:

http://10.10.110.160:9200/_cat/indices?v      -- Get请求 查看有多少索引

http://10.10.110.160:9200/benlaitest/_analyze?analyzer=standard  --查看分词结果

Elasticsearch基本命令

 

{
  "tokens": [
    {
      "token": "",
      "start_offset": 0,
      "end_offset": 1,
      "type": "<IDEOGRAPHIC>",
      "position": 0
    },
    {
      "token": "",
      "start_offset": 1,
      "end_offset": 2,
      "type": "<IDEOGRAPHIC>",
      "position": 1
    },
    {
      "token": "",
      "start_offset": 2,
      "end_offset": 3,
      "type": "<IDEOGRAPHIC>",
      "position": 2
    },
    {
      "token": "",
      "start_offset": 3,
      "end_offset": 4,
      "type": "<IDEOGRAPHIC>",
      "position": 3
    },
    {
      "token": "",
      "start_offset": 4,
      "end_offset": 5,
      "type": "<IDEOGRAPHIC>",
      "position": 4
    },
    {
      "token": "",
      "start_offset": 5,
      "end_offset": 6,
      "type": "<IDEOGRAPHIC>",
      "position": 5
    },
    {
      "token": "",
      "start_offset": 6,
      "end_offset": 7,
      "type": "<IDEOGRAPHIC>",
      "position": 6
    }
  ]
}
View Code

一 DSL查询命令 -基本查询

  1. term 匹配指定的文档单元(匹配的是分词后的词条,假如川普分词后为 川和普,那么term匹配川普是无结果的,要用term匹配'川'或者'普'),1 至少匹配1个 2匹配两个:
    {"terms":{"tag":["a","b"],"mininmum":1}} 
  2. match 根据不同的字段选择合适的分析器,一个很智能的查询器,可以通过指定他的参数来控制匹配行文 operator 控制关联的查询条件 and或者or:
    {"query":{match{"title":{"query":"a b }c","operation":"and"}}}
  3. multi_match 与match查询类似,不同的是它可以作用在多个字段上:
    {"query":{"multi_match":{"query":"a v b","fields":["title","content"]}}}
  4. query_string 查询 支持lucene的查询语法:
    {"query":{"query_string":{"query":"titlename:你好^10 +titlename:哈哈","default_field":"titlename"}}}
    {"query":{"query_string":{"query":"你好 中国","fields":["title","name"],"use_dis_max":true}}}
  5. range查询 只针对单个字段
    {"query":{"range":{"year":{"from":1700,"to":1900}}}}

bool查询,复合查询,可以将无限数目的查询封装在一起

{"query":{"bool":{"must":{"term":{"title":"中国"}},"should":{"term":{"name":""}}}}}

其他查询方式:

  1. boosting查询 两个查询封装一起的查询
  2. constant_score 恒定分值查询
  3. indices 针对多个索引进行查询
  4. custom_filter_score custom_boost_factor custom_score
  5.  ids
    {
      "query": {
        "ids": {
          "type": "product",
          "values": [
            "0001-2020774",
            "0001-2020775"
          ]
        }
      }
    }
    View Code

相关文章:

  • 2021-11-13
  • 2021-06-29
  • 2021-12-05
  • 2021-09-18
  • 2021-09-27
  • 2021-12-10
  • 2021-09-27
  • 2021-09-29
猜你喜欢
  • 2019-09-04
  • 2022-01-01
  • 2021-12-09
  • 2021-10-12
  • 2021-09-14
  • 2021-12-15
  • 2021-12-16
相关资源
相似解决方案