gpt4 book ai didi

elasticsearch - ES查询以匹配查询中尽可能多的单词

转载 作者:行者123 更新时间:2023-12-02 23:07:38 24 4
gpt4 key购买 nike

我的索引中有几百万个文档。
我有一个句子,想检索与许多单词匹配的文档。我只需要搜索一个字段content

curl -X GET "xxx.com:9200/test/_search?pretty" -H 'Content-Type: application/json' -d'
{
"query" : {
"bool" : { "must" : [{"term": {"content": {"value": "popular artworks of Banksy"}}}]
}}
}
'

我希望查询中包含尽可能多的单词的文档越多越好。如果文档中的文字出现了很多艺术品,类克斯语和一些流行文字,则应将其打高分。
另外,是否可以将比其他单词更常见的单词的匹配权重降低?比Banksy更受欢迎。我知道我可以使用升压。但是我不想手动设置这些值。如果可能,我希望它有一个隐含的理解。

最佳答案

添加带有索引数据,搜索查询和搜索结果的工作示例。
请参阅有关match_phrase查询和bool queries的ES文档以获取详细说明。
索引数据:

{
"content":"popular popular popular artworks artworks Banksy"
}
{
"content":"popular artworks Banksy"
}
{
"content":"popular popular artworks Banksy"
}
{
"content": "popular artworks Banksy Banksy"
}
{
"content": "popular popular popular artworks artworks artworks Banksy"
}
搜索查询:
    {
"query": {
"bool": {
"should": [
{
"match": {
"content": "popular artworks of Banksy"
}
},
{
"match_phrase":{
"content":"popular artworks Banksy Banksy"
}
}
]
}
}
}
搜索结果:
"hits": [
{
"_index": "test1",
"_type": "_doc",
"_id": "4",
"_score": 0.4776722,
"_source": {
"content": "popular artworks Banksy Banksy"
}
},
{
"_index": "test1",
"_type": "_doc",
"_id": "5",
"_score": 0.22413516,
"_source": {
"content": "popular popular popular artworks artworks artworks Banksy"
}
},
{
"_index": "test1",
"_type": "_doc",
"_id": "1",
"_score": 0.22279418,
"_source": {
"content": "popular popular popular artworks artworks Banksy"
}
},
{
"_index": "test1",
"_type": "_doc",
"_id": "3",
"_score": 0.21652403,
"_source": {
"content": "popular popular artworks Banksy"
}
},
{
"_index": "test1",
"_type": "_doc",
"_id": "2",
"_score": 0.21318543,
"_source": {
"content": "popular artworks Banksy"
}
}
]

关于elasticsearch - ES查询以匹配查询中尽可能多的单词,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64084049/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com