具有条件的对象列表上的 ElasticSearch MultiMatchQuery 匹配值

ElasticSearch MultiMatchQuery match value on list of objects with condition

我有一个索引,其中对象包含对象数组:

{
  "id": "someID",
  "tags": [],
  "people": [
    {
      "id": "userID",
      "role": "roleTARGET1",
      "firstName": "name",
      "lastName": "lastname",
      "fullName": "fullname"
    },
    {
      "id": "userID",
      "role": "role",
      "firstName": "name",
      "lastName": "lastname",
      "fullName": "fullname"
    },
    {
      "id": "userID",
      "role": "roleTARGET2",
      "firstName": "name",
      "lastName": "lastname",
      "fullName": "fullname"
    }
  ],
  "importantPerson": {
    "id": "userID",
    "role": "role",
    "firstName": "name",
    "lastName": "lastname",
    "fullName": "fullname"
  },
  "highlightedFields": {}
}

我的查询需要的工作方式是:

我在想在这种情况下可以使用某种异或结构。

我解析和生成查询的方式是通过 Java 中的 RestHighLevelClient,这是一个片段:

   private void addSearchQuery(BoolQueryBuilder query, List<Filter> filters) {

    String value = filters.get(0).getValues().get(0).getValue();
    String[] fields = new String[filters.size()];

    int i = 0;

    for (Filter filter : filters) {
        fields[i] = filter.getPath();
        i++;
    }

    addMultiMatchQuery(query, fields, value);
}

private void addMultiMatchQuery(BoolQueryBuilder query, String[] fields, String value) {
    query.filter(QueryBuilders.multiMatchQuery(value, fields).operator(Operator.AND).type(MultiMatchQueryBuilder.Type.BOOL_PREFIX));
}

关于如何完成此操作的任何想法?

java 代码或查询将不胜感激。

谢谢!

{
    "query": {
        "bool": {
            "should": [
                {
                    "bool": {
                        "must": {
                            "match": {"importantPerson.fullName": "fullname"}
                        }                         
                    }
                },
                {
                    "bool": {
                        "must": [
                            {"term": {"importantPerson.fullName": ""}},
                            {
                                "bool":{
                                "should":[
                                    {
                                        "term":{
                                            "people.role":"roleTARGET1"
                                        }
                                    },
                                    {
                                        "term":{
                                            "people.role":"roleTARGET2"
                                        }
                                    }
                                ]
                                }
                            }
                        ]
                    }
                }
            ]
        }
    }
}

确实如此 OR = should

(importantPerson's full name 匹配

OR

{ object empty

AND

`OR = role a or b`

} }