gpt4 book ai didi

elasticsearch - 组合filter和must in elasticsearch

转载 作者:行者123 更新时间:2023-12-02 23:07:05 24 4
gpt4 key购买 nike

在必须内部添加查询过滤器和分别具有查询过滤器和必须过滤器之间有什么区别?
我需要将过滤器查询应用于搜索,但是这两个查询中的任何一个对我来说都是相同的。我想知道是否有任何区别。
情况1:

  "query": {
"bool": {
"must": [
{
"term": {
"field": {
"value": "VALUE"
}
}
},
{
"bool": {
"filter": [
{
"script": {
"script": {
"source": """
return true;

"""
}
}
}
]
}
}
]
}
}
情况2:
  "query": {
"bool": {
"must": [
{
"term": {
"field": {
"value": "VALUE"
}
}
}
],
"filter": [
{
"script": {
"script": {
"source": """
return true;

"""
}
}
}
]
}
}
我认为它们没有区别,但我需要引用。问候。

最佳答案

这两个查询将完全相同地工作
请参阅boolean query上的文档以了解有关您的结构的更多信息

must: The clause (query) must appear in matching documents and willcontribute to the score.

filter: The clause (query) must appear in matching documents. Howeverunlike must the score of the query will be ignored. Filter clauses areexecuted in filter context, meaning that scoring is ignored andclauses are considered for caching.


合并多个 bool(boolean) 查询的第一个查询的结构:
{
"query": {
"bool": {
"must": [
{
"term": {},
"bool": {
"filter": {
"script": {}
}
}
}
]
}
}
}
第二个查询的结构,其中包括单个 bool(boolean) 查询:
{
"query": {
"bool": {
"must": [
{
"term": {}
}
],
"filter": [
{
"script": {}
}
]
}
}
}
如您所见,在两个搜索查询中,仅当同时满足术语查询和脚本查询条件时,文档才会匹配

关于elasticsearch - 组合filter和must in elasticsearch,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64464486/

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