简体   繁体   English

Elasticsearch [2.3]-建议查询不返回更新的文档

[英]Elasticsearch [2.3] - suggest query not returning updated document

I've been trying to update a few auto-suggest documents in elastic: 我一直在尝试用Elastic更新一些自动建议的文档:

{"update":{"_index":"my_autosuggest_index", "_type":"my_autosuggest_type", "_id": "123"}}
{"doc" : {my-updated-doc}, "doc_as_upsert" : true}

The update works, when directly asking for the updated doc 123 using 当直接使用来请求更新的文档123时,更新有效

GET /my_autosuggest_index/my_autosuggest_type/123

I do see the updated doc. 我确实看到了更新的文档。

However, when querying for the updated doc using: 但是,在使用以下方法查询更新的文档时:

/my_autosuggest_index/_suggest

{
  "hotels-suggest": {
    "text": "London",
    "completion": {
      "field": "suggest",
      "size": 10,
      "context": {
        "displayType": "Airports"
      }
    }
  }
}

I get doc 123 before the update. 我在更新前得到doc 123

Tried clearing the cache - still getting the non-updated doc. 尝试清除缓存-仍获取未更新的文档。

I could not find any documentation or think of any other explanation for this weird behavior. 对于这种奇怪的行为,我找不到任何文档,也没有想到任何其他解释。

Thanks. 谢谢。

We faced the same issue. 我们面临着同样的问题。 It occurs due to the way elasticsearch handles updates and deletes of documents. 它的发生是由于elasticsearch处理文档更新和删除的方式。

You can read a bit about it here 你可以在这里读到一些

All documents in elasticsearch are immutable. elasticsearch中的所有文档都是不可变的。 As the documents are immutable, when you update the document, the old document is marked for deletion and a new document is created. 由于文档是不可变的,因此在更新文档时,会将旧文档标记为删除并创建新文档。 The old document will be truly deleted when the segments in elasticsearch index merge. 当Elasticsearch索引中的段合并时,旧文档将被真正删除。 Here lies the problem. 问题就在这里。 Somehow in my case when we used the suggestion query we got both results. 就我而言,当我们使用建议查询时,我们得到了两个结果。

To overcome this you can force merge the segments after an update. 为了克服这个问题,您可以在更新后强制合并这些段。 This is slow but works. 这很慢,但是有效。

POST /index_name/_optimize?max_num_segments=1

I think the optimize api is deprecated. 我认为不建议使用优化API。

If it does not work the you can also use force merge 如果不起作用,您也可以使用强制合并

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM