如何在 Solr 中获取最后的索引记录
How to get last indexed record in Solr
在我的 Solr 核心中,我有 ID 字段,它是一个主键。我是这样定义的:
<field name="ID" type="string" indexed="true" stored="true" required="true" multiValued="false" />
我正在使用命令提示符为我的记录编制索引。之后我想查询以获取最后一个 ID。我的查询是这样的:
http://localhost:8983/solr/StorageCore/select?fl=ID&q=*%3A*&sort=ID%20desc
它给了我这个结果:
{
"responseHeader":{
"status":0,
"QTime":0,
"params":{
"q":"*:*",
"fl":"ID",
"sort":"ID desc"}},
"response":{"numFound":909,"start":0,"docs":[
{
"ID":"99"},
{
"ID":"98"},
{
"ID":"97"},
{
"ID":"96"},
{
"ID":"95"},
{
"ID":"94"},
{
"ID":"93"},
{
"ID":"92"},
{
"ID":"911"},
{
"ID":"910"}]
}
所以结果不是我想要的。我想要 911 而不是 99。我该如何解决这个问题?
更新
在@MatsLindh 和@Abhijit Bashetti 的协助下,我创建了一个类型为 int 的新字段,之后我复制了我所有的 uniqueKey 字段,即 ID 到新字段。所以它起作用了。我现在的查询回复是这样的:
{
"responseHeader":{
"status":0,
"QTime":2,
"params":{
"q":"idCopy:*",
"fl":"idCopy",
"sort":"idCopy desc",
"rows":"9999"}},
"response":{"numFound":909,"start":0,"docs":[
{
"idCopy":[911]},
{
"idCopy":[910]},
{
"idCopy":[909]},
{
"idCopy":[908]},
{
"idCopy":[907]},
{
"idCopy":[906]},
{
"idCopy":[905]},
{
"idCopy":[904]},
{
"idCopy":[903]},
{
"idCopy":[902]},
{
"idCopy":[901]},
{
"idCopy":[900]},
您需要将字段 ID
的 fieldType
从 string
更改为 int
。
应该是下面这样的。
<field name="IDS" type="int" indexed="true" stored="true" multiValued="false" docValues="true"/>
当您将 fieldType
作为 string
时,结果如下所示。
当您将 fieldType
作为 int
时,结果如下所示。
在我的 Solr 核心中,我有 ID 字段,它是一个主键。我是这样定义的:
<field name="ID" type="string" indexed="true" stored="true" required="true" multiValued="false" />
我正在使用命令提示符为我的记录编制索引。之后我想查询以获取最后一个 ID。我的查询是这样的:
http://localhost:8983/solr/StorageCore/select?fl=ID&q=*%3A*&sort=ID%20desc
它给了我这个结果:
{
"responseHeader":{
"status":0,
"QTime":0,
"params":{
"q":"*:*",
"fl":"ID",
"sort":"ID desc"}},
"response":{"numFound":909,"start":0,"docs":[
{
"ID":"99"},
{
"ID":"98"},
{
"ID":"97"},
{
"ID":"96"},
{
"ID":"95"},
{
"ID":"94"},
{
"ID":"93"},
{
"ID":"92"},
{
"ID":"911"},
{
"ID":"910"}]
}
所以结果不是我想要的。我想要 911 而不是 99。我该如何解决这个问题?
更新
在@MatsLindh 和@Abhijit Bashetti 的协助下,我创建了一个类型为 int 的新字段,之后我复制了我所有的 uniqueKey 字段,即 ID 到新字段。所以它起作用了。我现在的查询回复是这样的:
{
"responseHeader":{
"status":0,
"QTime":2,
"params":{
"q":"idCopy:*",
"fl":"idCopy",
"sort":"idCopy desc",
"rows":"9999"}},
"response":{"numFound":909,"start":0,"docs":[
{
"idCopy":[911]},
{
"idCopy":[910]},
{
"idCopy":[909]},
{
"idCopy":[908]},
{
"idCopy":[907]},
{
"idCopy":[906]},
{
"idCopy":[905]},
{
"idCopy":[904]},
{
"idCopy":[903]},
{
"idCopy":[902]},
{
"idCopy":[901]},
{
"idCopy":[900]},
您需要将字段 ID
的 fieldType
从 string
更改为 int
。
应该是下面这样的。
<field name="IDS" type="int" indexed="true" stored="true" multiValued="false" docValues="true"/>
当您将 fieldType
作为 string
时,结果如下所示。
当您将 fieldType
作为 int
时,结果如下所示。