Embed highlighter

Hi everyone, I need help.
I have to incorporate the highlighter is this my code on node.jd thanks

app.get('/search', function (req, res) {
let body = {
size: 100,
from: 0,
query: {
bool: {
_id: ,
must: [

      {
        "bool": {
          "should": [
            { "match": { title: req.query['q'] } },
            // { "match": { title: req.query['q'] } },
            { "match": { content: req.query['q'] } },
            { "match": { nome: req.query['q'] } },
            { "match": { cognome: req.query['q'] } },
            { "match": { dateToDay: req.query['q'] } },
            { "match": { groupName: req.query['q'] } }
          ]
        }

      }
      ,

      {
        "bool": {
          "must": [
            { "match": { userid: req.user.id } }
            //,
            //{ "match": { useridPadre: req.user.id } },

          ]
        }
      }


    ]
  }
}
// ,

// "highlight": {
//   "require_field_match": true,
//   "fields": {
//      "content":{}
//   }
// }

}

client.search({ body: body })// con index
.then(results => {
res.send(results.hits.hits);

})
.catch(err => {
  console.log(err)
  res.send([]);
});

})

please take your time to properly format your snippets. This is super hard to read.

Also, please mention what error messages are being returned when you try to add highlighting, this is super useful for debugging.

Also, have you tried to run that query in the kibana console (not in your programming language) just to see if it works in principle? That's usually a good start before trying to do this in any programming language.

hi, this query does work bat don't see the highlight. thanks
GET /_search?q='aws'
{
"query": {
"bool": {
"_id": ,
"must": [

      {
        "bool": {
          "should": [
            { "match": { "title": "aws" }},
            { "match": { "content": "aws" } },
            { "match": { "nome": "aws" } },
            { "match": { "cognome": "aws" } },
            { "match": { "dateToDay": "aws" } },
            { "match": { "groupName": "aws" } }
          ]
        }

      }
      ,

      {
        "bool": {
          "must": [
            { "match": { "userid": "5df6079a570a0b0017aea0e7" } }
          ]
        }
      }
    ]
  }
},
"highlight" : {
    "fields" : {
        "title" : {}
    }
}

}

can you share a fully reproducible example including index creation/mapping/document indexing, please? Thanks!

[quote="spinscale, post:4, topic:212566, full:true"]
can you share a fully reproducible example including index creation/mapping/document indexing, please? Thanks!

Hi, sorry if I'm not precise in what they ask me I'm new on elasticsearch.
The following is the code in node.js which it uses to create snippets. As you notice index = null.
Thank you

Fabio

Client.index({
index: "null",
//id: '1',
//type: 'constituencies',

      body: {
        "name": String(req.body.name),
        "surname": String(req.body.surname),
        "imageAccount": imageAccount1,
        //'String(req.body.imageAccount),

        "dateToDay": dataForm,
        "userid": arrayUser, //ho tolto le quadre
        // "userid": [String(list1)],

        "useridPadre": String(req.user.id),
        "title": String(req.body.title),
        "content": String(req.body.contenuto),
        //  "allBody": (String(req.body.title) +
        //    ' ' + String(req.body.content)),
        "show": false,
        "idGruppo": req.body.ddlGroup,
        "groupName": nota.nomeGruppo,
        "nome": String(nomeUt),
        "cognome": String(cognomeUt),
        "publicationState": req.body.DDLpublicationState

      }

good evening, can you help me?

I'm sorry, but this is not a fully reproducible example. See https://www.elastic.co/help

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.