使用多个字段而不是一个字段在Elasticsearch中升级文档

发布于 2025-01-26 07:27:43 字数 598 浏览 0 评论 0原文

此外,问题使用自定义ID字段中的Elasticsearch中的UPSERT文档现在,我需要从输入中使用2个以上字段的文档来列出文档。

以与上述问题相同的示例 -

示例数据:

table =“ trade” | tradeid =“ 1234” | qty = 100 | price = 100.00 | buyorsell =“ buy” | stock =“ abcd inc。”

如果我们在上述记录上收到修改:

table =“ trade” | tradeid =“ 1234” | qty = 120 |价格= 101.74 | buyorsell =“ buy” | stock =“ abcd inc。”

我需要根据TradeID和库存来提高。我找不到任何文档提及它。我实际上可以创建一个新的字段,即两个字段的串联,但我想避免它。

Further to question Upsert documents in Elasticsearch using custom ID field, now I need to upsert the documents with 2+ fields from the input.

Taking the same example as the above question -

Sample data:

TABLE="TRADE"|TradeID="1234"|Qty=100|Price=100.00|BuyOrSell="BUY"|Stock="ABCD Inc."

if we receive modification on the above record:

TABLE="TRADE"|TradeID="1234"|Qty=120|Price=101.74|BuyOrSell="BUY"|Stock="ABCD Inc."

I need to upsert based on TradeID and Stock both. I could not find any documentation on-site mentioning it. I could actually create a new field that is the concatenation of two fields but I want to avoid it.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

送君千里 2025-02-02 07:27:43

您需要使用TradeIdstock创建一个复合ID,

`document_id => "%{TradeID}-%{Stock}"`

但是,最好使用股票股票代替股票名称。

另一种方法是使用过滤器TradeIDstock值中创建一个一致的哈希,然后将其用作输出部分中的文档ID:

filter {
  ...
  fingerprint {
    source => ["TradeID", "Stock"]
    target => "[@metadata][id]"
  }
  ...
}
output {
  elasticsearch {
    ...
    document_id => "%{[@metadata][id]}"
    ...
  }
}

You need to create a compound ID with TradeID and Stock, something like

`document_id => "%{TradeID}-%{Stock}"`

It would be better to use a stock ticker instead of the stock name, though.

Another way is to use the fingerprint filter to create a consistent hash out of the TradeID and Stock values and then use that hash as the document ID in the output section:

filter {
  ...
  fingerprint {
    source => ["TradeID", "Stock"]
    target => "[@metadata][id]"
  }
  ...
}
output {
  elasticsearch {
    ...
    document_id => "%{[@metadata][id]}"
    ...
  }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文