代码之家  ›  专栏  ›  技术社区  ›  blue-sky

'验证失败:1:[index]不能与时间点一起使用;'}]

  •  0
  • blue-sky  · 技术社区  · 4 年前

    遵循本指南( https://www.elastic.co/guide/en/elasticsearch/reference/current/paginate-search-results.html )我创建了一个PIT ID,并使用该ID尝试使用查询对搜索结果进行分页:

    start_date = '2020-03-11T00:00:00Z'
    end_date = '2021-10-30T00:00:00Z'
    
    start_date = datetime.datetime.strptime(start_date, "%Y-%m-%dT%H:%M:%SZ")
    end_date = datetime.datetime.strptime(end_date, "%Y-%m-%dT%H:%M:%SZ")
    
    search_param = {
                    "size": 10000,
                    "query": {
    
                        "bool": {
                            "must": [
                                {"range": {"ts": {"gte": start_date, "lt": end_date}}}
                            ],
                            "should": [
                                {"exists": {"field": "data.test1"}},
                                {"exists": {"field": "data.test2"}},
                                {"exists": {"field": "data.test3"}}
                            ],
                            "minimum_should_match": 1
                        }
                    },
            "pit": {
            "id": "0_uxAwILMTQxMV9ldmVudHMWTFhXQ3NrYWNSRDZMVlJzMlhPbjZVZwAWaEZZNUVOUF9SdTY5V0tMTzZyaEVtdwAAAAAAAA2Q6xZaeFkycDRKWVNxYXo0b252cXBLREtRCzE0MTFfZXZlbnRzFkxYV0Nza2FjUkQ2TFZSczJYT242VWcBFkMycTFXRmh2U3pDWXlPTXJtVlJUVWcAAAAAAAAs7BwWYmExNFdBNE9Sb1NNcklWNGgydURfUQEWTFhXQ3NrYWNSRDZMVlJzMlhPbjZVZwAA",
            "keep_alive": "1m"
                },
                    "sort": [
                        {"ts": "asc"}
                    ]
                }
    

    然后,我使用以下命令调用查询:

    result = elastic_connector.search(index="data_store", body=search_param, ignore=[400, 404])
    print('result' , result)
    

    打印结果为:

    result {'error': {'root_cause': [{'type': 'action_request_validation_exception', 'reason': 'Validation Failed: 1: [indices] cannot be used with point in time;'}], 'type': 'action_request_validation_exception', 'reason': 'Validation Failed: 1: [indices] cannot be used with point in time;'}, 'status': 400}
    

    我使用的是elasticsearch 7.11。这里有一个相关的问题: https://github.com/elastic/elasticsearch/issues/69974 但我不确定同样的问题是否适用于这里。

    我应该如何构造查询以接受PIT参数?

    0 回复  |  直到 4 年前
        1
  •  8
  •   Markus    4 年前

    从文档中:

    如果提供坑,则不能指定 <target> 在请求路径中。[ 1 ]

    带有维修点参数的搜索请求不得指定索引、路由和首选项,因为这些参数是从时间点复制的。[ 2 ]

    因此,创建带有索引信息的PIT,并在没有索引信息的情况下使用它。