简体   繁体   中英

Elasticsearch highlight doesn't highlight results

I'm testing ES and I would highlight the results of a query but it doesn't work with my simple query :

            var myQuery = {
                "query": {
                    "bool": {
                        "must": {
                            "query_string": {
                                "query": mySearchText + "~3"
                            }
                        }
                    }
                },
                "highlight": {
                    "fields": {
                        "*":{}
                    }
                }
            };

Where did I made some mistake please ? Thanks for all.

PS : this is a sample of document

            {
                "id_stage" : "3897",
                "intitule_stage" : "Le surendettement des particuliers",
                "objectifs" : "Acqu\u00e9rir les comp\u00e9tences suivantes :\r\n*Conna\u00eetre de mani\u00e8re approfondie les dispositions de la loi sur le surendettement des particuliers.\r\n*Ma\u00eetriser la proc\u00e9dure.",
                "contenu" : "*Introduction :\r\n-D\u00e9finitions. Bilans chiffr\u00e9s. Statistiques.\r\n-La proc\u00e9dure de la Loi Borloo (juin 2003 et d\u00e9cret 2004) : le \"r\u00e9tablissement personnel\".\r\n-La loi Lagarde (juillet 2010) et ses d\u00e9crets d'application.\r\n-Pr\u00e9vention du surendettement.\r\n*Les conditions g\u00e9n\u00e9rales d'application de la proc\u00e9dure de surendettement :\r\n-Un d\u00e9biteur, personne physique de bonne foi.\r\n-Un \u00e9tat de surendettement.\r\n-Des dettes non professionnelles exigibles et \u00e0 \u00e9choir.\r\n*La proc\u00e9dure devant la commission de surendettement :\r\n-Ouverture, d\u00e9roulement et cl\u00f4ture de la proc\u00e9dure.\r\n*La proc\u00e9dure devant le juge de l'ex\u00e9cution :\r\n-Absence de contestation des mesures recommand\u00e9es par la commission de surendettement.\r\n-Contestation des mesures recommand\u00e9es par la commission.\r\n-Cons\u00e9quences de la force ex\u00e9cutoire.",
                "pre_requis" : "",
                "mmp" : "",
                "sessions" : [{
                        "id_session" : "4775",
                        "debut" : "2016-11-29",
                        "date_fin" : "2016-12-02",
                        "ville" : "PARIS"
                    }
                ]
            }

If you would like to highlight the relevant segments on all fields, you should use

"highlight": {
  "fields": {
    "_all":{}
  }
}

Instead of

"highlight": {
  "fields": {
    "*":{}
  }
}

I am sure you must have solved this by now but for others facing the same issue, here is what I think you might have missed

A field can only be used for highlighting if the original string value is available, either from the _source field or as a stored field.

The _all field is not present in the _source field and it is not stored or enabled by default, and so cannot be highlighted. There are two options. Either store the _all field or highlight the original fields.

http://nocf-www.elastic.co/guide/en/elasticsearch/reference/current/mapping-all-field.html#highlighting-all-field

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM