0

I have a percolator query in ES as the following-

"query": {
    "bool": {
        "filter": [{
            "nested": {
                "path": "Person",
                "query": {
                    "bool": {
                        "filter": [{
                            "term": {
                                "Person.FirstName": "John"
                            }
                        }, {
                            "term": {
                                "Person.LastName": "Smith"
                            }
                        }, {
                            "term": {
                                "Person.Age": 30
                            }
                        }]
                    }
                }
            }
        }, {
            "nested": {
                "path": "Person",
                "query": {
                    "bool": {
                        "filter": [{
                            "term": {
                                "Person.FirstName": "Mark"
                            }
                        }, {
                            "term": {
                                "Person.LastName": "Watson"
                            }
                        }, {
                            "term": {
                                "Person.Age": 40
                            }
                        }]
                    }
                }
            }
        }]
    }
}

and I am using the following percolator document-

{
    "query": {
        "percolate": {
            "field": "query",
            "document": {
                "Person": [{
                    "Id": 001,
                    "FirstName": "John",
                    "LastName": "Smith",
                    "Age": 30
                }, {
                    "Id": 002,
                    "FirstName": "Baz",
                    "LastName": "Portman",
                    "Age": 30
                }, {
                    "Id": 003,
                    "FirstName": "Foo",
                    "LastName": "Bar",
                    "Age": 40
                }, {
                    "Id": 004,
                    "FirstName": "Mark",
                    "LastName": "Watson",
                    "Age": 40
                }, {
                    "Id": 005,
                    "FirstName": "John",
                    "LastName": "Foo",
                    "Age": 30
                }, {
                    "Id": 006,
                    "FirstName": "John",
                    "LastName": "Smith",
                    "Age": 25
                }]
            }
        }
    }
}

This document returns the percolator query successfully, but is there a way to identify the items in the Person array in the document that satisfied the query, e.g., in this case- [0,3]? Or, return the Id fields of the documents?

Mapping

{
    "mappings": {
        "dynamic": "false",
        "properties": {
            "Person": {
                "type": "nested",
                "properties": {
                    "Id": {
                        "type": "keyword"
                    },
                    "FirstName": {
                        "type": "keyword"
                    },
                    "LastName": {
                        "type": "keyword"
                    },
                    "Age": {
                        "type": "integer"
                    }
                }
            }
        }
    }
}

I can't use separate documents for the items in Person array since there is an AND condition for comparing multiple Person objects within the same query.

0 Answers0