【发布时间】:2021-11-02 18:28:51
【问题描述】:
这里是 Elasticsearch 新手。我正在尝试查找名称中包含 foo 的文档,但希望优先考虑包含 bar 的文档,即具有 bar 的文档将位于列表顶部。结果没有顶部带有 bar 的结果。 boost 这里似乎没有任何效果,可能我不明白 boost 在这里是如何工作的。在这里感谢任何帮助。
query: {
bool: {
should: [
{
query_string: {
query: `name:foo*bar*`,
boost: 5
}
},
{
query_string: {
query: `name:*foo*`,
}
}
]
}
}
示例文档结构:
{
"name": "foos, one two three",
"type": "car",
"age": 10
}
{
"name": "foos, one two bar three",
"type": "train",
"age": 30
}
索引映射
{
"detail": {
"mappings": {
"properties": {
"category": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"name": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"servings": {
"properties": {
"name": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
}
}
}
}
}
}
}
【问题讨论】:
-
可以添加示例文档吗
-
嗨 Jaspreet - 我添加了示例文档结构。它不是一个真实的文件。这些太大而无法包含,但示例捕获了我感兴趣的字段,并且它是文档中的顶级字段。
标签: elasticsearch elasticsearch-query