如何在Solr中获取最后一个索引记录

xuo3flqw  于 2022-11-05  发布在  Solr
关注(0)|答案(1)|浏览(140)

在我的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]},
ruarlubt

ruarlubt1#

您需要将字段IDfieldTypestring更改为int
应该是下面的样子。

<field name="IDS"  type="int" indexed="true" stored="true" multiValued="false" docValues="true"/>

当您将fieldType设为string时,结果如下所示。

当您将fieldType设为int时,结果如下所示。

相关问题