Définir et utiliser un modèle de recherche

Cheat Sheet

PUT /shakespeare
{
 "mappings": {
   "properties": {
    "speaker": {"type": "keyword"},
    "play_name": {"type": "keyword"},
    "line_id": {"type": "integer"},
    "speech_number": {"type": "integer"}
   }
 }
}


curl -H 'Content-Type: application/x-ndjson' -XPOST 'localhost:9200/bank/account/_bulk?pretty' --data-binary @accounts.json
curl -H 'Content-Type: application/x-ndjson' -XPOST 'localhost:9200/shakespeare/doc/_bulk?pretty' --data-binary @shakespeare_6.0.json


GET _cat/nodes?v

GET _cat/indices?v

### Recherche un terms via un template
GET _search/template
{
    "source": {
        "query": {
            "bool": {
                "must": [
                    {
                        "wildcard": {
                            "firstname.keyword": {
                                "value": "{{first}}"
                            }
                        }
                    }
                ]
            }
        }
    },
    "params": {
        "first": "*"
    }
}


GET _search/template
{
    "source": {
        "query": {
            "bool": {
                "must": [
                    {
                        "wildcard": {
                            "firstname.keyword": {
                                "value": "{{first}}{{^first}}*{{/first}}"
                            }
                        }
                    }
                ]
            }
        }
    }
}


GET _search/template
{
    "source": {
        "query": {
            "bool": {
                "must": [
                    {
                        "wildcard": {
                            "firstname.keyword": {
                                "value": "{{first}}{{^first}}*{{/first}}"
                            }
                        }
                    },
                    {
                        "wildcard": {
                            "lastname.keyword": {
                                "value": "{{last}}{{^last}}*{{/last}}"
                            }
                        }
                    }
                ]
            }
        }
    },
    "params":{
        "last": "Duke"
    }
}


POST _script/account_lookup_by_name
{
    "script": {
        "lang": "mustache",
        "source": {
            "query": {
                "bool": {
                    "must": [
                        {
                            "wildcard": {
                                "firstname.keyword": {
                                    "value": "{{first}}{{^first}}*{{/first}}"
                                 }
                            }
                        },
                        {
                            "wildcard": {
                                "lastname.keyword": {
                                    "value": "{{last}}{{^last}}*{{/last}}"
                                }
                            }
                        }
                    ]
                }
            }
        }
    }
}


GET _search/template
{
    "id": "account_lookup_by_name",
    "params": {
        "first": "Amber",
        "last": "DUke"
    }
}

#### Valeur par défaut
GET _search/template
{
    "id": "account_lookup_by_name",
}