Skip to content

Elasticsearch 使用示例

218字小于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 ObjectParent/Child
优点文档存储在一起,读取性能高父子文档存在不通的type,可以独立更新吗,互补影响
缺点更新父或子文档时需要更新这个文档为了维护Join关系,需要占用部分内存读取性能较差
场景子文档偶尔更新,查询频繁子文档更新频繁

陕ICP备2021014644号-1