【问题标题】:Elasticsearch search on different index with different field of same clusterElasticsearch搜索具有相同集群的不同字段的不同索引
【发布时间】:2021-11-22 07:26:14
【问题描述】:

我需要帮助来搜索具有不同字段的同一集群的不同索引。例如:如果我有一个集群名称 demo,其中有 2 个索引 menu_itemspurchase_orders。两个索引都包含要搜索的不同列。索引 menu_items 包含“label”字段,索引 purchase_orders 包含“id”和“supplier_reference”字段。

    $params  = [
        'index'   => 'menu_items,purchase_orders',
        '_source' => 'label,id,supplier_reference',
        'body'    => [
            'query' => [
                'bool' => [
                    'must' => [
                        'multi_match' => [
                            'query'  => $keyword,
                            'type'   => 'bool_prefix',
                            'fields' => ['label', 'id', 'supplier_reference'],
                        ],
                    ],
                ],
            ],
        ],
    ];

现在,如果我正在搜索两个索引中都可用的任何术语“3312”,因此该查询运行良好,而另一个术语“供应商”当时在另一个索引中不可用,我得到了一个错误。 有人可以在这里帮忙吗?我怎样才能做到这一点?我们如何在两个或多个不同的索引中找到字段?

【问题讨论】:

  • 这感觉像是Multi Search API 的工作。
  • 是的,在发布之前,我浏览了您提供的链接。但我不知道我在上面的代码中犯了哪个错误。 - @nitrin0
  • 错误信息是什么?
  • 得到类似下面的消息:BadRequest400Exception {"error":{"root_cause":[{"type":"query_shard_exception","re​​ason":"failed to create query: For input string: \ "Sup\"","index":"menu_items","index_uuid":"cE5R0uuFQa-JsZ8tkMN4uA"},{"type":"query_shard_exception","re​​ason":"创建查询失败:对于输入字符串:\" Sup\"","index":"purchase_orders","index_uuid":"L2KxaN29QT2KbWsT0cNxiA"}],"type":"search_phase_execution_exception","re​​ason":"所有分片失败","phase":"query","分组":true,"failed_shards"

标签: php laravel elasticsearch


【解决方案1】:

我面临如下所述的问题,作为我在这里找到的解决方案,我们需要进行正确的映射。

与映射相关,Elasticsearch 具有检测文档字段类型并生成模式并将其应用于整个索引的内置能力。但这会导致错误,而两个索引对于同一字段具有不同的数据类型。例如:如果 index1 具有 long 数据类型的 id 字段,而 index2 具有 string 数据类型的 id 字段。当时搜索操作给出了与我在问题中描述的 id 字段相关的搜索错误。

【讨论】:

    猜你喜欢
    • 2015-02-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-12-02
    • 1970-01-01
    • 1970-01-01
    • 2015-09-22
    • 1970-01-01
    相关资源
    最近更新 更多