Elasticsearch 使用示例
约 220 字小于 1 分钟
2023-12-06
查询所有数据
GET /kdaiyu_report_measurement/_search
{
"query": {
"match_all": {}
}
}
多条件查询
GET kdaiyu_report_measurement/_search
{
"query": {
"bool": {"must":[
{"term":{"u_id": 10001}},
{"term":{"sex": "男"}},
{"term":{"school_type": 985}}
]
}
}
}
分页查询
GET /kdaiyu_patient_check_item_stats/_search
{
"query": {
"match_phrase": {"PCA_APPLY_HOSPITAL": "西安体检机构"}
},
"size": 50,
"from": 100
}
nested查询
GET /kdaiyu_report_measurement_03/_search
{
"query": {
"bool": {"must":[
{
"nested":{
"path": "company",
"query":{"match_phrase":{"company.name": "联通"}}
}
},
{
"nested":{
"path": "school",
"query":{"match_phrase":{"school.name": "北京大学"}}
}
}
]
}
}
}
重建索引
POST _reindex
{
"source": {
"index": "kdaiyu_report_measurement",
"size": 5000
},
"dest": {
"index": "kdaiyu_report_measurement_03"
}
}
ES 多层查询
https://blog.csdn.net/tuposky/article/details/80988915
https://blog.csdn.net/laoyang360/article/details/82950393
对比 | Nested Object | Parent/Child |
---|---|---|
优点 | 文档存储在一起,读取性能高 | 父子文档存在不通的type,可以独立更新吗,互补影响 |
缺点 | 更新父或子文档时需要更新这个文档 | 为了维护Join关系,需要占用部分内存读取性能较差 |
场景 | 子文档偶尔更新,查询频繁 | 子文档更新频繁 |