Apache Solr JSON 查询本地参数
Apache Solr JSON Querying Local Params
在 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
在 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