【问题标题】:Searching after indexing in ElasticSearch在 ElasticSearch 中建立索引后进行搜索
【发布时间】:2016-05-30 12:39:18
【问题描述】:

我想索引 10 亿条记录。每条记录有 2 个属性(属性 1 和属性 2)。 在属性 1 中具有相同值的每条记录都必须合并。例如,我有两条记录

attribute1  attribute2
1   4
1   6

我的弹性文档必须是

{
   "attribute1": "1"
   "attribute2": "4,6"
}

由于数据量巨大,我必须读取大量(大约1000条记录)并根据上述规则将它们合并(在内存中),然后在ElasticSearch中搜索它们并将它们与搜索结果合并,然后索引/重新索引他们。 总之,我必须分别按批量搜索和索引。 我实现了这条规则,但在某些情况下,Elastic 不会返回所有结果,并且某些文档已被重复索引。 在每个索引之后,我都会刷新 ElasticSearch,以便为下一次搜索做好准备。但在某些情况下它不起作用。 我的索引设置如下:

{
"test_index": {
    "settings": {
        "index": {
            "refresh_interval": "-1",
            "translog": {
                "flush_threshold_size": "1g"
            },
            "max_result_window": "1000000",
            "creation_date": "1464577964635",
            "store": {
                "throttle": {
                    "type": "merge"
                }
            }
        },
        "number_of_replicas": "0",
        "uuid": "TZOse2tLRqGk-vHRMGc2GQ",
        "version": {
            "created": "2030199"
        },
        "warmer": {
            "enabled": "false"
        },
        "indices": {
            "memory": {
                "index_buffer_size": "40%"
            }
        },
        "number_of_shards": "5",
        "merge": {
           "policy": {
                "max_merge_size": "2g"
            }
        }
    }
}

我该如何解决这个问题?

有没有其他设置可以处理这种情况?

【问题讨论】:

    标签: search elasticsearch indexing


    【解决方案1】:

    在您的批量命令中,您需要使用index 操作首次出现,然后使用带有脚本的update 来更新您的attribute2 属性:

    { "index" : { "_index" : "test_index", "_type" : "test_type", "_id" : "1" } }
    { "attribute1" : "1", "attribute2": [4] }
    { "update" : { "_index" : "test_index", "_type" : "test_type", "_id" : "1" } }
    { "script" : { "inline": "ctx._source.attribute2 += attr2", "params" : {"attr2" : 6}}}
    

    在第一次index 操作后,您的文档将如下所示

    {
       "attribute1": "1"
       "attribute2": [4]
    }
    

    第二次update 操作后,您的文档将如下所示

    {
       "attribute1": "1"
       "attribute2": [4, 6]
    }
    

    请注意,update 也可以仅与 doc_as_upsertscript 一起使用。

    【讨论】:

    • 我的问题是为什么有时当我索引数据并刷新弹性并立即搜索时,弹性不返回结果?
    • 如何刷新索引?我看到你的refresh_interval 设置是-1,这意味着“从不刷新”。
    • 批量索引后。我用 API 调用刷新。
    • 您确定您的搜索返回所有文档并且您没有达到最大值size?请描述您是如何进行搜索的?
    • 我发送带有查询的计数请求并获取结果计数,然后发送具有相同查询和先前计数结果大小的搜索请求以获取所有文档。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-03-03
    • 1970-01-01
    • 2023-01-19
    • 2022-06-18
    • 1970-01-01
    • 2015-10-21
    • 2019-12-29
    相关资源
    最近更新 更多