Skip to content

Commit

Permalink
[DOCS] _index_prefix for highligh matched_fields
Browse files Browse the repository at this point in the history
Enhance documenation to explain that "_index_prefix" subfield must
be added to `matched_fields` param for highlighting a main field.
When doing prefix queries on fields that are indexed with prefixes,
"_index_prefix" subfield is used. If we try to highlight the main
field, we may not get any results. "_index_prefix" subfield must
be added to `matched_fields` which instructs ES to use matches
from "_index_prefix" to highlight the main field.
  • Loading branch information
mayya-sharipova committed Dec 12, 2024
1 parent d514315 commit 0c8b956
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
26 changes: 26 additions & 0 deletions docs/reference/mapping/params/index-prefixes.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,29 @@ PUT my-index-000001
}
}
--------------------------------

`index_prefixes` parameter instructs {ES} to create a subfield "._index_prefix". This
field will be used to do fast prefix queries. When doing highlighting, add "._index_prefix"
subfield to the `matched_fields` parameter to highlight the main field based on the
found matches of the prefix field, like in the request below:

[source,console]
--------------------------------
GET my-index-000001/_search
{
"query": {
"prefix": {
"full_name": {
"value": "ki"
}
}
},
"highlight": {
"fields": {
"full_name": {
"matched_fields": ["full_name._index_prefix"]
}
}
}
}
--------------------------------
15 changes: 15 additions & 0 deletions docs/reference/mapping/types/search-as-you-type.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,21 @@ GET my-index-000001/_search
"my_field._3gram"
]
}
},
"highlight": {
"fields": {
"my_field": {
"matched_fields": ["my_field._index_prefix"] <1>
}
}
}
}
--------------------------------------------------
// TEST[continued]

<1> Adding "my_field._index_prefix" to the `matched_fields` allows to highlight
"my_field" also based on matches from "my_field._index_prefix" field.

[source,console-result]
--------------------------------------------------
{
Expand All @@ -126,6 +136,11 @@ GET my-index-000001/_search
"_score" : 0.8630463,
"_source" : {
"my_field" : "quick brown fox jump lazy dog"
},
"highlight": {
"my_field": [
"quick <em>brown fox jump lazy</em> dog"
]
}
}
]
Expand Down

0 comments on commit 0c8b956

Please sign in to comment.