Skip to content

Commit 0c8b956

Browse files
[DOCS] _index_prefix for highligh matched_fields
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.
1 parent d514315 commit 0c8b956

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

docs/reference/mapping/params/index-prefixes.asciidoc

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,29 @@ PUT my-index-000001
5454
}
5555
}
5656
--------------------------------
57+
58+
`index_prefixes` parameter instructs {ES} to create a subfield "._index_prefix". This
59+
field will be used to do fast prefix queries. When doing highlighting, add "._index_prefix"
60+
subfield to the `matched_fields` parameter to highlight the main field based on the
61+
found matches of the prefix field, like in the request below:
62+
63+
[source,console]
64+
--------------------------------
65+
GET my-index-000001/_search
66+
{
67+
"query": {
68+
"prefix": {
69+
"full_name": {
70+
"value": "ki"
71+
}
72+
}
73+
},
74+
"highlight": {
75+
"fields": {
76+
"full_name": {
77+
"matched_fields": ["full_name._index_prefix"]
78+
}
79+
}
80+
}
81+
}
82+
--------------------------------

docs/reference/mapping/types/search-as-you-type.asciidoc

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,21 @@ GET my-index-000001/_search
9797
"my_field._3gram"
9898
]
9999
}
100+
},
101+
"highlight": {
102+
"fields": {
103+
"my_field": {
104+
"matched_fields": ["my_field._index_prefix"] <1>
105+
}
106+
}
100107
}
101108
}
102109
--------------------------------------------------
103110
// TEST[continued]
104111

112+
<1> Adding "my_field._index_prefix" to the `matched_fields` allows to highlight
113+
"my_field" also based on matches from "my_field._index_prefix" field.
114+
105115
[source,console-result]
106116
--------------------------------------------------
107117
{
@@ -126,6 +136,11 @@ GET my-index-000001/_search
126136
"_score" : 0.8630463,
127137
"_source" : {
128138
"my_field" : "quick brown fox jump lazy dog"
139+
},
140+
"highlight": {
141+
"my_field": [
142+
"quick <em>brown fox jump lazy</em> dog"
143+
]
129144
}
130145
}
131146
]

0 commit comments

Comments
 (0)