ES查询语句

ES 查询语句

1.查询总数,ES最大查询返回10000条,kibana查询时添加 ?rest_total_hits_as_int

GET test/_search?rest_total_hits_as_int
{
"query": {
"match_all": {}
}
}

2.根据某一项的聚合:ElasticSearch Terms Aggregation

聚合查询报错:Fielddata is disabled on text fields by default. Set fielddata=true on [title] in order to load fielddata in memory by uninverting the inverted index. Note that this can however use significant memory. Alternatively use a keyword field instead.
解决方案:https://blog.csdn.net/u010569419/article/details/90081232

3.清空索引下所有数据

POST test/_delete_by_query
{
"query": {
"match_all": {}
}
}

4. ES重复项目删除

POST ys_related_sv/_delete_by_query
{
"query": {
"bool" : {
"must_not": [
{
"exists": {"field": "vid"}
}
]
}

}
}

https://www.jianshu.com/p/58443004fb36

注意:需要删除索引重建才能设置!!!

开启Text的fielddata=true, 在ES中默认fielddata是false,因为开启text的,注意:这样会取消es的倒排索引功能,并且很吃内存
https://blog.csdn.net/tangbin0505/article/details/108493034fielddata后对内存的占用很高
【这边文章写得很好】
https://www.cnblogs.com/sanduzxcvbnm/p/12092298.html

5.es查询不存在的字段

GET ys_related_sv/_search
{
"query": {
"bool" : {
"must": [
{
"exists": {"field": "vid"}
}
]
}

}
}

6.es查询存在的字段

GET ys_related_sv/_search
{
"query": {
"bool" : {
"must_not": [
{
"exists": {"field": "vid"}
}
]
}

}
}

ES查询语句

上一篇:eval解析JSON中的注意点


下一篇:题解 SP220 PHRASES - Relevant Phrases of Annihilation