如何获取solr中的最后一个索引记录

时间:2020-03-26 10:22:51

标签: 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 的新字段,之后我将所有我的唯一ID 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]},

1 个答案:

答案 0 :(得分:1)

您需要将字段php.ini的{​​{1}}从fieldType更改为ID

应该如下所示。

string

int设为<field name="IDS" type="int" indexed="true" stored="true" multiValued="false" docValues="true"/> 时,结果如下所示。

Image with string type

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

enter image description here