#创建索引
PUT /employee
{
"settings": {
"number_of_shards": 1,
"number_of_replicas": 1
}
}
#分布式节点建设(更新replicas状态)
PUT /employee/_settings
{
"settings": {
"number_of_replicas": 1
}
}
#创建索引,指定id建立索引(指定id全量修改索引)
PUT /employee/_doc/1
{
"name" : "小镇",
"age":10
}
#指定id 部分字段修改
POST /employee/_update/1
{
"doc": {
"name" : "小王"
}
}
#指定_create防止重复创建
POST /employee/_create/1/
{
"name" : "小李呀",
"age":22
}
#使用搜索全部
GET /employee/_search
#获取指定id
GET /employee/_doc/1
#不指定id建立索引
POST /employee/_doc
{
"name" : "小李呀",
"age":22
}
#删除索引
DELETE /employee
#结构化创建
PUT /employee/
{
"settings": {
"number_of_shards": 1,
"number_of_replicas": 1
},
"mappings": {
"properties": {
"name" : {"type": "text"},
"age" : {"type": "integer"}
}
}
}
#es查询语句 排序/聚合/分页
GET /employee/_search
{
"query": {
"match": {
"name": "王"
}
},
"sort": [
{
"age": {
"order": "desc"
}
}
],
"aggs": {
"group_by_age": {
"terms": {
"field": "age"
}
}
},
"from": 1,
"size": 20
}
#Bool查询 must/must not/should
GET /movie/_search
{
"query": {
"bool": {
"should": [
{"match": {
"title": "测试 with ce"
}},
{"match": {
"other": "测试 with csdsa"
}}
]
}
}
}
#不同的multi_query的type和multi_match得分不一样
#best_fields默认,取积分最高的。
#tie_breaker将其他因素以0.3的倍数考虑进去
GET /movie/_search
{
"query": {
"dis_max": {
"queries": [
{"match": {
"title": "测试 with ce"
}},
{"match": {
"other": "测试 with csdsa"
}}
],
"tie_breaker": 0.3
}
}
}
#type
#most_fields取命中分值相加作为分数(加权共同影响模式)
#cross_fields以分词为单位计算栏位总分(词导向匹配)
GET /movie/_validate/query
{
"explain" : true,
"query": {
"multi_match": {
"query": "sam job",
"fields": ["title","remark"],
"operator": "or",
"type": "most_fields"
}
}
}
#query_string 便于利用AND OR NOT
GET /movie/_search
{
"query": {
"query_string": {
"fields": ["title"],
"query": "steve AND dsa OR dasd"
}
}
}
1.match查询,按照字段上定义的分词分析后去索引内查询
2.term查询,不进行词的分析,直接去索引查询,及搜索关键词和精确查询
3.match分词后的and和or