gpt4 book ai didi

java - 在我的 Elasticsearch 查询中将逗号放在哪里

转载 作者:行者123 更新时间:2023-11-30 22:48:57 25 4
gpt4 key购买 nike

我正在使用这个 Elasticquent我的 Laravel 应用程序的 ES 包。

但我不确定应该在查询字符串中的什么位置放置逗号。我知道如果我在内部数组中有多个元素,我必须加上逗号。但是所有的数组都需要逗号吗?这两个查询似乎都很好,这就是我想知道的原因。我想做最好的实践,所以这就是我问的原因。

'filtered' => [
'query' => [
'match' => ['title' => Input::get('query')]
],
'filter'=> [
'bool' => [
'must' => [
['term' => [ 'type' => 1] ],
['term' => [ 'state' => 22] ],
['term' => [ 'city' => ] ],
[ 'range' => [
'price' => [
'gte' => ,
'lte' => ,
]
]
]
]
]
],
],

还有更多逗号(,)

'filtered' => [
'query' => [
'match' => ['title' => Input::get('query')]
],
'filter'=> [
'bool' => [
'must' => [
['term' => [ 'type' => 1] ],
['term' => [ 'state' => 22] ],
['term' => [ 'city' => ] ],
[ 'range' => [
'price' => [
'gte' => ,
'lte' => ,
]
]
]
],
],
],
],

它们似乎都有效。这是使用此包的完整查询示例:

$posts = Post::searchByQuery([
'filtered' => [
'filter' => [
'not' => [
'terms' => ['title' => ['impedit', 'voluptatem']]
]
],
'query' => [
"bool" => [
'must' => [
'multi_match' => [
'query' => Input::get('query', ''),
'fields' => [ "title^2", "content"]
],
],
"should" => [
'match' => [
'tags' => [
"query" => Input::get('query', ''),
"type" => "phrase"
]
]
]
]
],
],
]);

此外,是否可以像我在查询 #1 和 #2 中那样在 MUST 中使用 3 个过滤器,或者您能否只在 should {} 中放置多个过滤器

最佳答案

在您的第二个查询版本中,放置尾随逗号通常用于指示其他参数。由于您只有一组参数,因此不需要额外的逗号。例如,在 filter => block 之后放置一个逗号,表示您在 filter 之后还有其他语句。另外,为什么要为解析器保留额外的字符?

 'filtered' => [
'query' => [
'match' => ['title' => Input::get('query')]
],
'filter'=> [
'bool' => [
'must' => [
['term' => [ 'type' => 1] ],
['term' => [ 'state' => 22] ],
['term' => [ 'city' => ] ],
[ 'range' => [
'price' => [
'gte' => ,
'lte' => ,
]
]
]
], // <=== Other operators to filter on?
], // <=== Other operations other than query and filter?
],
],

对于你的第二个问题,根据 docs,可以通过将它们包装在 bool 过滤器中来应用多个过滤器。 :

'

filtered' => [
'query' => [
'match' => ['title' => Input::get('query')]
],
'filter'=> [
'bool' => [
'must' => [
['term' => [ 'type' => 1] ],
['term' => [ 'state' => 22] ],
['term' => [ 'city' => ] ],
[ 'range' => [
'price' => [
'gte' => ,
'lte' => ,
]
]
]
],
'must_not' => [
['term' => ['state' => 23] ] // <=== Additional must clause
]
]
],
],

关于java - 在我的 Elasticsearch 查询中将逗号放在哪里,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28723418/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com