[英]Elasticsearch query is not working as expected
I have search query like this which is not working and giving me error [bool] malformed query, expected [END_OBJECT] but found [FIELD_NAME]我有这样的搜索查询,它不起作用并给我错误[bool] 格式错误的查询,应为 [END_OBJECT] 但找到 [FIELD_NAME]
array:2 [
"index" => "esdata"
"body" => array:1 [
"query" => array:2 [
"bool" => array:1 [
"should" => array:1 [
0 => array:1 [
"multi_match" => array:2 [
"query" => "History"
"fields" => array:1 [
0 => "*"
]
]
]
]
]
"terms" => array:1 [
"_id" => array:1 [
0 => "ae499e9d-8c9c-4d25-9f88-28f8fde64e10_*"
]
]
]
]
]
so I changed it to所以我把它改成
array:2 [
"index" => "esdata"
"body" => array:1 [
"query" => array:1 [
"bool" => array:2 [
"should" => array:1 [
0 => array:1 [
"multi_match" => array:2 [
"query" => "History"
"fields" => array:1 [
0 => "*"
]
]
]
]
"must" => array:1 [
0 => array:1 [
"match" => array:1 [
"_id" => "ae499e9d-8c9c-4d25-9f88-28f8fde64e10_*"
]
]
]
]
]
]
]
but this is giving empty result但这给出了空的结果
I am not familiar with the syntax of PHP, but the first query should be in the below format我不熟悉PHP的语法,但第一个查询应该是下面的格式
{
"query": {
"bool": {
"should": [
{
"multimatch": {
"query": "History",
"fields": "*"
}
},
{
"terms": {
"_id": [
1,
2,
3
]
}
}
]
}
}
}
And the second query can be modified into:第二个查询可以修改为:
{
"query": {
"bool": {
"should": [
{
"multimatch": {
"query": "History",
"fields": "*"
}
}
],
"must": {
"match": {
"_id": "ae499e9d-8c9c-4d25-9f88-28f8fde64e10_"
}
}
}
}
}
Note: match
query works on analyzed text, whereas terms query will give you the result only when the search term exactly matches.注意:
match
查询适用于分析的文本,而术语查询仅在搜索词完全匹配时才会为您提供结果。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.