elasticsearch,Filter,elasticsearch" /> elasticsearch,Filter,elasticsearch" />

Filter 术语数组上的ElasticSearch筛选器正在过滤掉所有术语

Filter 术语数组上的ElasticSearch筛选器正在过滤掉所有术语,filter,elasticsearch,Filter,elasticsearch,在我的应用程序中,用户属于角色列表,而对象具有与其关联的角色列表以确定可见性。我正在尝试创建一个查询,以确保用户至少属于对象所需的一个组 以下是我的索引配置: { "settings": { "analysis": { "filter": { "nGram_filter": { "type": "nGram", "min_gram": 2

在我的应用程序中,用户属于角色列表,而对象具有与其关联的角色列表以确定可见性。我正在尝试创建一个查询,以确保用户至少属于对象所需的一个组

以下是我的索引配置:

{
    "settings": {
        "analysis": {
            "filter": {
                "nGram_filter": {
                    "type": "nGram",
                    "min_gram": 2,
                    "max_gram": 12,
                    "token_chars": []
                }
            },
            "analyzer": {
                "nGram_analyzer": {
                    "type": "custom",
                    "tokenizer": "whitespace",
                    "filter": [
                        "lowercase",
                        "asciifolding",
                        "nGram_filter"
                    ]
                },
                "whitespace_analyzer": {
                    "type": "custom",
                    "tokenizer": "whitespace",
                    "filter": [
                        "lowercase",
                        "asciifolding"
                    ]
                }
            }
        }
   },
    "mappings": {
        "team" : {
            "dynamic": "strict",
            "properties" : {
                "id": {
                    "type": "string",
                    "index": "not_analyzed"
                },
                "object": {
                    "type": "string",
                    "index": "not_analyzed"
                },
                "roles": {
                    "type": "string",
                    "index": "not_analyzed"
                },
                "name": {
                    "type": "string",
                    "index_analyzer": "nGram_analyzer",
                    "search_analyzer": "whitespace_analyzer"
                },
                "text": {
                    "type": "string",
                    "index_analyzer": "nGram_analyzer",
                    "search_analyzer": "whitespace_analyzer"
                }
            }
        }
    }
}
以下是我编制索引的一些示例数据: 通过localhost验证:9200/index/_search?q=name:employee_1&pretty

{
    "id":"lsJ17K4sgQVfd",
    "roles: ["OwnerslsJ17K21px6VX","AdminslsJ17K21px6VX"],
    "object":"contact",
    "name":"employee_1",
    "text":"lsJ17K4sgQVfd employee_1 employee_1 employee_1@lsj17k1nysk75.com"
}
以下是我试图执行的查询,以查找同一联系人:

{
    "_source": ["id", "object", "name"],
    "size": 30,
    "query": {
        "filtered": {
            "query": {
                "bool": {
                    "should": {
                        "multi_match": {
                            "query": "employee_1",
                            "type": "cross_fields",
                            "operator": "or",
                            "fields": ["name^2", "text"],
                            "minimum_should_match": "50%",
                            "fuzziness": "AUTO"
                        }
                    },
                    ...,
                    "minimum_should_match": 1
                }
            },
            "filter": {
                "terms": {
                    "roles": [ "AdminslsJ17K21px6VX", "lsJ17K3gHCH4P" ]
                }
            }
        }
    },
    "suggest": {
        "text": "employee_1",
        "text_suggestion": {
            "term": {
                "size": 3,
                "field": "name",
                "sort": "score",
                "suggest_mode": "missing",
                "prefix_length": 1
            }
        }
    }
}

如果我删除了filter子句,那么我会得到结果,但一旦我将其添加回,所有内容都会再次被过滤掉。要表示我希望结果至少有一个共同角色,正确的方法是什么?

上面的查询按预期工作,唯一的问题是我的测试用例在索引完全填充之前执行。在进行第一次查询之前添加一个短的等待时间解决了问题