我使用elasticsearch
进行搜索查询,在某些情况下,当我搜索boolean
字段时,我可以看到搜索结果与搜索结果相反...
这是我的搜索查询:
[
"sort" => [
[
"_score" => "desc"
]
]
"size" => 50
"from" => 0
"terminate_after" => 100
"query" => [
"bool" => [
"must" => [
[
"query_string" => [
"query" => "sales*"
"analyze_wildcard" => true
"default_operator" => "AND"
"boost" => 1
]
]
[
"bool" => [
"should" => [
[
"match" => ["gender" => 0]
]
]
]
]
]
"must_not" => []
]
]
]
例如,我每页有50个结果,我看到我的结果有40个gender = 0
,但其中10个有gender = 1
,我尝试term queries
但它没有按照我的预期工作..我不希望任何性别的值为1。
我找不到任何关于我的问题,如果有人有任何文档或解决方案让我知道..
提前致谢
答案 0 :(得分:0)
在我的弹性搜索数组上进行了一些更改之后,我尝试了filter search
来获取我的确切值,现在它可以正常工作了。
现在这是我的代码:
[
"sort" => [
[
"_score" => "desc"
]
]
"size" => 50
"from" => 100
"terminate_after" => 100
"query" => [
"bool" => [
"must" => [
[
"query_string" => [
"query" => "sales*"
"analyze_wildcard" => true
"default_operator" => "AND"
"boost" => 1
]
]
]
"filter" => [
[
"bool" => [
"should" => [
[
"term" => ["gender" => 0]
]
]
]
]
]
"must_not" => []
]
]
]