【发布时间】:2015-04-20 09:54:31
【问题描述】:
我有一个表达式/查询: ("text" started_with "hello" OR "text" started_with "hi") OR ("select" is "first_option" AND "correct" is "true" )。你能告诉我如何在 Elastic Search 中正确使用 bool 和 filter 查询来解决这个表达式吗?
【问题讨论】:
标签: elasticsearch
我有一个表达式/查询: ("text" started_with "hello" OR "text" started_with "hi") OR ("select" is "first_option" AND "correct" is "true" )。你能告诉我如何在 Elastic Search 中正确使用 bool 和 filter 查询来解决这个表达式吗?
【问题讨论】:
标签: elasticsearch
您可以使用“prefix query”以及boolean query 和term query 来实现给定的表达式/查询。尝试如下
{
"bool": {
"should": [
{
"prefix": {
"text": {
"value": "hello"
}
}
},
{
"prefix": {
"text": {
"value": "hi"
}
}
},
{
"bool": {
"must": [
{
"term": {
"select": [
"first_option"
]
}
},
{
"term": {
"correct": [
"true"
]
}
}
]
}
}
]
}
}
【讨论】:
"query" : {match_all: {}}, "filter": {"or":[ { "prefix": { } } .... ]?