Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DOCS] _index_prefix for highligh matched_fields #118569

Merged
merged 2 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 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,30 @@ 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"]
}
}
}
}
--------------------------------
// TEST[continued]
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