【问题标题】:ElasticSearch bool query return null immediately after insert dataElasticSearch bool 查询在插入数据后立即返回 null
【发布时间】:2026-02-01 19:40:01
【问题描述】:

我在我的索引中插入多个对象,当我在插入数据后立即从索引中获取查询时,我的输出为空 但是在我重试查询近 8 小时后,我的结果有一些内容

我的查询是:

GET myIndex/_search
{
  "size": 1, 
  "query": {
    "bool": {
      "filter": [
        {
          "term": {
            "identifier": {
              "value": "597713-2"
            }
          }
        },
        {
          "term": {
            "organizationUnitCode": {
              "value": "00001"
            }
          }
        }
      ]
    }
  }
}

这是我的索引设置:

{
  "myIndex" : {
    "settings" : {
      "index" : {
        "creation_date" : "1633957331203",
        "number_of_shards" : "1",
        "number_of_replicas" : "1",
        "uuid" : "V_MtNZ57S4CFmlKwS_0wyA",
        "version" : {
          "created" : "7020099"
        },
        "provided_name" : "myIndex"
      }
    }
  }
}

【问题讨论】:

  • 请分享 myIndex/_setting?pretty response
  • @hamidbayat 我更新我的问题并添加设置
  • refresh 过程发生后,该文档将是可搜索的。默认设置为 1 秒。显然您没有更改默认设置。但要确保将 index.refresh_interval 设置为 1s

标签: c# asp.net elasticsearch nest


【解决方案1】:

Elasticsearch 接近实时引擎,这意味着如果您索引并立即尝试查询,它将无法正常工作(可能需要至少一秒钟才能使内容可搜索,但准确时间取决于您的环境和配置)。

欲了解更多信息:Elasticsearch docs

【讨论】:

  • 我尝试在刷新间隔后进行查询,但我没有得到正确的结果