javaelasticsearchspring-data-elasticsearch

Spring Data elasticsearch @Query annotation


My JSON doc is like this: Meu documento JSON é assim:

{
"query" : {
    "bool": {
        "minimum_should_match": 1,
        "should": [
        {
          "bool":   { "must": [{"match": {"txt": "p"}},
                    {"match": {"nm": "p"}}
            ]
          }
        },
        {
          "bool": { "must": [{"match": {"txt": "p"}}
            ]
          }
        },
        {
          "bool": { "must": [{"match": {"nm": "p"}}
            ]
          }
        }
        ]
        }
},
"highlight": {
    "number_of_fragments" : 1,
    "order": "score",
    "boundary_scanner": "sentence", 
    "fragment_size" : 300,
    "pre_tags" : ["<tag1>"],
    "post_tags" : ["</tag1>"],
    "fragmenter": "span", 
    "fields" : {
        "nm": {},
        "txt": {}
    }
  },
  "_source": false
}

How should I write the query method using @Query annotation ? (or if there is any other method that I can put the highlight) ? Como devo escrever o método de consulta usando a anotação @Query? (ou se houver algum outro método que eu consiga colocar o highlight) ?

observation:highlight it's very important observação:destaque que é muito importante

Thanks for any suggestion. Obrigado por qualquer sugestão.


Solution

  • You should put the query part into the @Query annotation, see the relevant documentation.

    For the highlight definition, you can use the @Highlight annotation, check the reference documentation