我有三个字段 - 一个是整数类型(field1),另外两个是十进制类型(field2,field3)。我希望能够通过所有字段进行查询。这些单独的查询在我的情况下很有用:
$params = [
'index' => 'test_index',
'type' => 'text_index_type',
'body' => [
'query' => [
'match' => [
'field1' => '12'
]
]
]
];
这个查询效果很好:
$params = [
'index' => 'test_index',
'type' => 'text_index_type',
'body' => [
'query' => [
'multi_match' => [
'query' => '345',
'fields' => ['field2', 'field3']
]
]
]
];
但是,如果我将它们合并:
$params = [
'index' => 'test_index',
'type' => 'text_index_type',
'body' => [
'query' => [
'match' => [
'field1' => '12'
],
'multi_match' => [
'query' => '345',
'fields' => ['field2', 'field3']
]
]
]
];
我收到错误:
未捕获的异常' Elasticsearch \ Common \ Exceptions \ BadRequest400Exception' ... [匹配]格式错误的查询,意外[FIELD_NAME]找到[multi_match]
那么,这有什么问题,我该如何解决?
PS。就SQL而言,这就是我想要实现的目标:
SELECT * FROM mytable where field1 = 12 or field2 = 345 or field3 = 345