使用stac-fastapi Search API时OR条件查询报错,求正确写法
正确构造stac-fastapi Search API的OR条件查询请求
要解决RequestValidationError问题,你需要严格按照stac-fastapi的查询规则构造OR条件,核心是把多个合法查询条件放入query.or数组中,每个条件仅使用允许的操作符(eq、ne、lt、lte、gt、gte)。
示例请求体
以查询云量小于10或平台为Sentinel-2的影像为例,正确的POST请求JSON体如下:
{ "query": { "or": [ { "eo:cloud_cover": { "lt": 10 } }, { "platform": { "eq": "Sentinel-2" } } ] } }
关键注意事项
or字段的值必须是数组,每个元素是一个独立的属性查询对象- 每个查询对象只能使用官方允许的操作符,不能自定义操作符
- 可同时组合
and条件实现更复杂的逻辑,比如:
{ "query": { "and": [ { "eo:cloud_cover": { "lte": 20 } }, { "or": [ { "platform": { "eq": "Sentinel-2" } }, { "platform": { "eq": "Landsat-8" } } ] } ] } }
内容的提问来源于stack exchange,提问作者Esteban Lombardozzi
相关产品推荐
相关产品推荐

