在Solr文档中,它重点介绍了如何使用GET参数定义查询,但很少提供有关如何使用更好的结构化JSON POST支持完成相同任务的信息。我一直无法找到任何比表面层次解释更深入的文档。
特别是,我正在尝试在我的查询中使用本地参数,并想知道如何使用JSON POST而不是GET参数来完成以下操作:
http://localhost:8983/solr/city/query?sort={!sfield=location pt=35.5514,-97.4075}geodist() asc&q={!geofilt sfield=location pt=35.5514,-97.4075 d=5}
根据JSON Request API / Parameters Mapping,您的查询将映射到:
{
"sort": "{!sfield=location pt=35.5514,-97.4075}geodist() asc",
"query": "{!geofilt sfield=location pt=35.5514,-97.4075 d=5}"
}
只是为了完成@MatsLindh的答案,你可以使用通常的参数名称,只要你将它们包装在params
中(不需要映射),例如:
file.json
{
"params": {
"q":"{!geofilt sfield=location pt=35.5514,-97.4075 d=5}",
"sort":"{!sfield=location pt=35.5514,-97.4075}geodist() asc",
"wt": "json",
"indent": "true"
}
}
使用curl的请求示例:
curl -H "Content-Type: application/json" -X "POST" --data @file.json http://localhost:8983/solr/city/query