* Documentation for match_only_text field Signed-off-by: Rishabh Maurya <rishabhmaurya05@gmail.com> * Address pr comments Signed-off-by: Rishabh Maurya <rishabhmaurya05@gmail.com> * Doc review Signed-off-by: Fanit Kolchina <kolchfa@amazon.com> * Apply suggestions from code review Co-authored-by: Nathan Bower <nbower@amazon.com> Signed-off-by: kolchfa-aws <105444904+kolchfa-aws@users.noreply.github.com> * Apply suggestions from code review Co-authored-by: Nathan Bower <nbower@amazon.com> Signed-off-by: kolchfa-aws <105444904+kolchfa-aws@users.noreply.github.com> --------- Signed-off-by: Rishabh Maurya <rishabhmaurya05@gmail.com> Signed-off-by: Fanit Kolchina <kolchfa@amazon.com> Signed-off-by: kolchfa-aws <105444904+kolchfa-aws@users.noreply.github.com> Co-authored-by: Fanit Kolchina <kolchfa@amazon.com> Co-authored-by: kolchfa-aws <105444904+kolchfa-aws@users.noreply.github.com> Co-authored-by: Nathan Bower <nbower@amazon.com>
3.3 KiB
3.3 KiB
layout, title, nav_order, has_children, parent, grand_parent, redirect_from
layout | title | nav_order | has_children | parent | grand_parent | redirect_from | ||
---|---|---|---|---|---|---|---|---|
default | Token count | 70 | false | String field types | Supported field types |
|
Token count field type
A token count field type stores the number of analyzed tokens in a string.
Example
Create a mapping with a token count field:
PUT testindex
{
"mappings": {
"properties": {
"sentence": {
"type": "text",
"fields": {
"num_words": {
"type": "token_count",
"analyzer": "english"
}
}
}
}
}
}
{% include copy-curl.html %}
Index three documents with text fields:
PUT testindex/_doc/1
{ "sentence": "To be, or not to be: that is the question." }
{% include copy-curl.html %}
PUT testindex/_doc/2
{ "sentence": "All the world’s a stage, and all the men and women are merely players." }
{% include copy-curl.html %}
PUT testindex/_doc/3
{ "sentence": "Now is the winter of our discontent." }
{% include copy-curl.html %}
Search for sentences with fewer than 10 words:
GET testindex/_search
{
"query": {
"range": {
"sentence.num_words": {
"lt": 10
}
}
}
}
{% include copy-curl.html %}
The response contains one matching sentence:
{
"took" : 8,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 1,
"relation" : "eq"
},
"max_score" : 1.0,
"hits" : [
{
"_index" : "testindex",
"_type" : "_doc",
"_id" : "3",
"_score" : 1.0,
"_source" : {
"sentence" : "Now is the winter of our discontent."
}
}
]
}
}
Parameters
The following table lists the parameters accepted by token count field types. The analyzer
parameter is required; all other parameters are optional.
Parameter | Description |
---|---|
analyzer |
The analyzer to be used for this field. Specify an analyzer without token filters for optimal performance. Required. |
boost |
A floating-point value that specifies the weight of this field toward the relevance score. Values above 1.0 increase the field's relevance. Values between 0.0 and 1.0 decrease the field's relevance. Default is 1.0. |
doc_values |
A Boolean value that specifies whether the field should be stored on disk so that it can be used for aggregations, sorting, or scripting. Default is false . |
enable_position_increments |
A Boolean value that specifies whether position increments should be counted. To avoid removing stopwords, set this field to false . Default is true . |
index |
A Boolean value that specifies whether the field should be searchable. Default is true . |
null_value |
A value to be used in place of null . Must be of the same type as the field. If this parameter is not specified, the field is treated as missing when its value is null . Default is null . |
store |
A Boolean value that specifies whether the field value should be stored and can be retrieved separately from the _source field. Default is false . |