Hi everyone,
I set the following _source and highlight clauses in my search body:
{
"_source":
[
"field_1",
"field_2"
],
"highlight":{
"order":"score",
"fragment_size":70,
"number_of_fragments":3,
"type":"plain",
"pre_tags":["\u003cspan class \"highlight\"\u003e"],
"post_tags":["\u003c/span\u003e"],
"fields":{
"field_1":{"force_source":true},
"field_2":{"force_source":true},
"field_3":{"force_source":true},
"field_4":{"force_source":true},
}
}
According to https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-request-highlighting.html#_force_highlighting_on_source, I understood that, setting :force_source = true in the field highlight, if it occurs a matching on that field, it would be retrieved in the _source clause.
However, this does not happen with my search. The returned _source clause was:
hits":
[
{
"_index": "index_name",
"_type": "type_name",
"_id": "3288191",
"_score": 1897.5596,
"_source": {
"field_1": "201700000030",
"field_2": {
"id": 3,
"desc": "foo"
}
},
"highlight": {
"field_3": ["something <span class=\"highlight\">search term</span>"],
"field_4": [": another <span class=\"highlight\">search term</span> <span class=\"highlight\">search term</span>", ": foo bar - <span class=\"highlight\">search term</span>]
}
Did I miss something or the "force_source
" in this feature has nothing to with the _source
clause?
If that's the case, how can I achieve this solution: retrieving a field in the _source
clause only if there is a matching highlight on it?
Thanks,
Guilherme