天天看点

elasticsearch常用查询语句

创建一个索引

//smq-test为索引名,setting下面放的是分片数和副本数。

//mapping下面放的test是type类型,properties下面放的是索引/type下的字段类型

PUT smq-test

{

“settings”:{

“number_of_shards”: 3,

“number_of_replicas”: 1

},

“mappings”:{

“test”:{

“properties”:{

“titlea”:{“type”:“text”},

“description”:{“type”:“text”},

“price”:{“type”:“double”},

“onSale”:{“type”:“boolean”},

“typea”:{“type”:“text”},

“createDate”:{“type”:“date”}

}

}

}

}

复制索引数据到另外一个索引中:

POST _reindex

{

“source”: {

“index”: “ihr-baseinfo”

},

“dest”: {

“index”: “songmingqi-test”

}

}

删除索引中全部数据:

POST songmingqi-test/baseinfo/_delete_by_query?conflicts=proceed

{

“query”: {

“match_all”: {}

}

}

根据条件删除索引中的数据:

GET ihr-exammaster-*/_delete_by_query

{

“query”: {

“match”: {

“card_no”: “D”

}

}

}

去重:

GET test-songmingqi/baseinfo/_search

{

“query”: {

“bool”: {

“must”: [

{“match_all”: {}}

]

}

},

“from”: 0

, “size”: 20,

“aggregations”:{

“COUNT(distinct(xman_id))”:{

“cardinality”: {

“field”: “(xman_id)”

}

}

}

}

继续阅读