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 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 --查看分词结果
{
"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
}
]
}
一 DSL查询命令 -基本查询
-
term 匹配指定的文档单元(匹配的是分词后的词条,假如川普分词后为 川和普,那么term匹配川普是无结果的,要用term匹配'川'或者'普'),1 至少匹配1个 2匹配两个:
{"terms":{"tag":["a","b"],"mininmum":1}} -
match 根据不同的字段选择合适的分析器,一个很智能的查询器,可以通过指定他的参数来控制匹配行文 operator 控制关联的查询条件 and或者or:
{"query":{match{"title":{"query":"a b }c","operation":"and"}}} -
multi_match 与match查询类似,不同的是它可以作用在多个字段上:
{"query":{"multi_match":{"query":"a v b","fields":["title","content"]}}} -
query_string 查询 支持lucene的查询语法:
{"query":{"query_string":{"query":"titlename:你好^10 +titlename:哈哈","default_field":"titlename"}}} {"query":{"query_string":{"query":"你好 中国","fields":["title","name"],"use_dis_max":true}}} -
range查询 只针对单个字段
{"query":{"range":{"year":{"from":1700,"to":1900}}}}
bool查询,复合查询,可以将无限数目的查询封装在一起
{"query":{"bool":{"must":{"term":{"title":"中国"}},"should":{"term":{"name":"帅"}}}}}
其他查询方式:
- boosting查询 两个查询封装一起的查询
- constant_score 恒定分值查询
- indices 针对多个索引进行查询
- custom_filter_score custom_boost_factor custom_score
-
ids
View Code
{ "query": { "ids": { "type": "product", "values": [ "0001-2020774", "0001-2020775" ] } } }