Skip to content

Instantly share code, notes, and snippets.

@hkulekci
Last active September 9, 2023 04:53
Show Gist options
  • Save hkulekci/0d173e61b960d45a66b6573d36e1b4bc to your computer and use it in GitHub Desktop.
Save hkulekci/0d173e61b960d45a66b6573d36e1b4bc to your computer and use it in GitHub Desktop.
Percolator Field with Nested Query
PUT testindex1
{
  "mappings": {
    "properties": {
      "search": {
        "properties": {
          "query": { 
            "type": "percolator" 
          }
        }
      },
      "actors": { 
        "type": "nested",
        "properties": {
          "type": {
            "type": "keyword"
          },
          "name": {
            "type": "text"
          }
        }
      }
    }
  }
}



PUT testindex1/_doc/1
{
  "search": {
    "query": {
      "nested": {
        "path": "actors",
        "query": {
          "bool": {
            "must": [
              {
                "term": {
                  "actors.type": "cartoon"
                } 
              },
              {
                "match": {
                  "actors.name": "barbie"
                } 
              }
            ]
          }
        }
      }
    }
  }
}




GET testindex1/_search
{
  "query": {
    "bool": {
      "filter": {
        "percolate": {
          "field": "search.query",
          "document": {
            "id": 1,
            "actors": [
              {
                "type": "cartoon",
                "name": "barbie"
              },
              {
                "type": "real",
                "name": "ken"
              }
            ]
          }
        }
      }
    }
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment