ES 查询以匹配查询中尽可能多的单词
ES query to match as many words from the query
我的索引中有几百万个文档。
我有一个句子,想检索匹配尽可能多的单词的文档。我只需要搜索一个字段 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 和一些流行的 - 它应该被评为高分。
此外,是否可以降低比其他词出现频率更高的词的匹配权重?喜欢比 Banksy 更受欢迎。我知道我可以使用 boost。但我不想手动设置这些值。如果可能的话,我希望它有一个隐含的理解。
添加包含索引数据、搜索查询和搜索结果的工作示例。
请参阅 match_phrase query and 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"
}
}
]
我的索引中有几百万个文档。
我有一个句子,想检索匹配尽可能多的单词的文档。我只需要搜索一个字段 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 和一些流行的 - 它应该被评为高分。 此外,是否可以降低比其他词出现频率更高的词的匹配权重?喜欢比 Banksy 更受欢迎。我知道我可以使用 boost。但我不想手动设置这些值。如果可能的话,我希望它有一个隐含的理解。
添加包含索引数据、搜索查询和搜索结果的工作示例。
请参阅 match_phrase query and 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"
}
}
]