Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save samyranavela/00fec1c71270a4e8ea02b5dcdeeb34dd to your computer and use it in GitHub Desktop.
Save samyranavela/00fec1c71270a4e8ea02b5dcdeeb34dd to your computer and use it in GitHub Desktop.
Quelques requêtes Elasticsearch utilisées lors de la démonstration Lucene @LorraineJug
//-- pertinence et idf (Jean-Claude Jean après ville=Rueil)
{
"query": {
"bool": {
"should": [
{
"text": {
"nom": "jean"
}
},
{
"text": {
"lieux": "rueil"
}
}
],
"must": [],
"must_not": [],
"minimum_number_should_match": 1
}
}
}
//-- pertinence et idf (Jean-Claude Jean après ville=Rueil) avec explain
{
"explain": 1,
"query": {
"bool": {
"should": [
{
"text": {
"nom": "jean"
}
},
{
"text": {
"lieux": "rueil"
}
}
],
"must": [],
"must_not": [],
"minimum_number_should_match": 1
}
}
}
//-- retourne des objets de types différents (utiliser les deux types dans requête http)
//-- exercice : pour quoi les personnes se retrouvent en premier ?
{
"from": 0,
"size": 20,
"query": {
"bool": {
"should": [
{
"text": {
"nom": "york"
}
},
{
"text": {
"titre": "York"
}
}
],
"must": [],
"must_not": [],
"minimum_number_should_match": 1
}
}
}
//-- highlight et auto-complétion
{
"from": 0,
"size": 20,
"fields": [
"nom.untouched"
],
"query": {
"query_string": {
"default_field": "nom.comp",
"query": "ce"
}
},
"highlight": {
"number_of_fragments": 0,
"fields": {
"nom.comp": {}
}
}
}
//-- utilisation du champs nom.basic pour faire la différence avec une recherche exacte
//-- sans nom.basic
{
"from": 0,
"size": 20,
"query": {
"bool": {
"should": [
{
"text": {
"nom": "céline"
}
}
],
"must_not": [],
"minimum_number_should_match": 1
}
}
}
//-- avec nom.basic
{
"from": 0,
"size": 20,
"query": {
"bool": {
"should": [
{
"text": {
"nom": "céline"
}
},
{
"text": {
"nom.basic": "céline"
}
}
],
"must_not": [],
"minimum_number_should_match": 1
}
}
}
//-- fuzzy
{
"query": {
"bool": {
"must": [
{
"fuzzy": {
"nom": {
"value": "schvartzeneger",
"min_similarity": 0.7
}
}
}
],
"must_not": [],
"should": []
}
}
}
//-- dimminuer la min_similarity
{
"query": {
"bool": {
"must": [
{
"fuzzy": {
"nom": {
"value": "schvartzenegar",
"min_similarity": 0.6
}
}
}
],
"must_not": [],
"should": []
}
}
}
//-- stallone maintenant
{
"query": {
"bool": {
"must": [
{
"fuzzy": {
"nom": {
"value": "stalone",
"min_similarity": 0.7
}
}
}
],
"must_not": [],
"should": []
}
}
}
//-- rajouter un prefix_length
//-- sans prefix_length
{
"query": {
"bool": {
"must": [
{
"fuzzy": {
"nom": {
"value": "celin",
"min_similarity": 0.7
}
}
}
],
"must_not": [],
"should": []
}
}
}
//-- avec prefix_length
{
"query": {
"bool": {
"must": [
{
"fuzzy": {
"nom": {
"value": "celin",
"min_similarity": 0.7,
"prefix_length": 2
}
}
}
],
"must_not": [],
"should": []
}
}
}
//-- facettes
{
"query": {
"matchAll": {}
},
"facets": {
"genre": {
"terms": {
"field": "genre",
"all_terms": true
}
},
"pays": {
"terms": {
"field": "pays",
"all_terms": true
}
},
"langue": {
"terms": {
"field": "langue",
"all_terms": true
}
}
}
}
//-- facettes + filtre
{
"query": {
"matchAll": {}
},
"filter": {
"term": {
"langue": "français"
}
},
"facets": {
"genre": {
"terms": {
"field": "genre",
"all_terms": true
}
},
"pays": {
"terms": {
"field": "pays",
"all_terms": true
}
},
"langue": {
"terms": {
"field": "langue",
"all_terms": true
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment