Thanks Carly/Christian,
Here is the query:
{
"from": 0,
"size": 20,
"profile": true,
"query": {
"bool": {
"must": [
{
"query_string": {
"query": "147490666442",
"fields": [
"all_text^1.0",
"identifier^1.0"
],
"type": "best_fields",
"default_operator": "or",
"max_determinized_states": 10000,
"enable_position_increments": true,
"fuzziness": "AUTO",
"fuzzy_prefix_length": 0,
"fuzzy_max_expansions": 50,
"phrase_slop": 0,
"escape": false,
"auto_generate_synonyms_phrase_query": true,
"fuzzy_transpositions": true,
"boost": 1.0
}
}
],
"filter": [
{
"query_string": {
"query": "module:\"Alerts\"",
"fields": [
],
"type": "best_fields",
"default_operator": "or",
"max_determinized_states": 10000,
"enable_position_increments": true,
"fuzziness": "AUTO",
"fuzzy_prefix_length": 0,
"fuzzy_max_expansions": 50,
"phrase_slop": 0,
"escape": false,
"auto_generate_synonyms_phrase_query": true,
"fuzzy_transpositions": true,
"boost": 1.0
}
}
],
"adjust_pure_negative": true,
"boost": 1.0
}
},
"_source": {
"includes": [
],
"excludes": [
"attachment",
"audit",
"audits",
"note",
"notes",
"children",
"alert_xml"
]
},
"aggregations": {
"state": {
"terms": {
"field": "state.keyword",
"size": 10,
"min_doc_count": 1,
"shard_min_doc_count": 0,
"show_term_doc_count_error": false,
"order": [
{
"_count": "desc"
},
{
"_key": "asc"
}
]
}
},
"category": {
"terms": {
"field": "category.keyword",
"size": 10,
"min_doc_count": 1,
"shard_min_doc_count": 0,
"show_term_doc_count_error": false,
"order": [
{
"_count": "desc"
},
{
"_key": "asc"
}
]
},
"aggregations": {
"type": {
"terms": {
"field": "type_name.keyword",
"size": 10,
"min_doc_count": 1,
"shard_min_doc_count": 0,
"show_term_doc_count_error": false,
"order": [
{
"_count": "desc"
},
{
"_key": "asc"
}
]
}
}
}
},
"business_date_week": {
"date_range": {
"field": "business_date",
"format": "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'",
"ranges": [
{
"from": "now/d-1w",
"to": "now"
}
],
"keyed": false
}
},
"business_date_month": {
"date_range": {
"field": "business_date",
"format": "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'",
"ranges": [
{
"from": "now/d-1M",
"to": "now"
}
],
"keyed": false
}
},
"business_date_year": {
"date_range": {
"field": "business_date",
"format": "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'",
"ranges": [
{
"from": "now/d-1y",
"to": "now"
}
],
"keyed": false
}
}
},
"highlight": {
"max_analyzed_offset": 51200,
"fragment_size": 75,
"highlight_query": {
"bool": {
"must": [
{
"query_string": {
"query": "147490666442",
"fields": [
"all_text^1.0",
"identifier^1.0"
],
"type": "best_fields",
"default_operator": "or",
"max_determinized_states": 10000,
"enable_position_increments": true,
"fuzziness": "AUTO",
"fuzzy_prefix_length": 0,
"fuzzy_max_expansions": 50,
"phrase_slop": 0,
"escape": false,
"auto_generate_synonyms_phrase_query": true,
"fuzzy_transpositions": true,
"boost": 1.0
}
}
],
"adjust_pure_negative": true,
"boost": 1.0
}
},
"require_field_match": false,
"fields": {
"*_custom_tl2": {
},
"bu_name": {
},
"reason": {
},
"identifier": {
},
"type_name": {
},
"owner_name": {
},
"*_custom_ti2": {
},
"rfi_attachment": {
},
"*_custom_td2": {
},
"description": {
},
"display_name": {
},
"type": {
},
"type_abbr_name": {
},
"priority_identifier": {
},
"rfi": {
},
"*_custom_txt": {
},
"score_field2": {
},
"step": {
},
"state": {
},
"alert_name": {
}
}
}
}
And the mapping...
{
"david_index": {
"mappings": {
"dynamic_templates": [
{
"custom_txt": {
"match": "*_custom_txt",
"mapping": {
"analyzer": "index_text_en",
"copy_to": "all_text",
"search_analyzer": "search_text",
"type": "text"
}
}
},
{
"custom_ti": {
"match": "*_custom_ti",
"mapping": {
"copy_to": [
"all_text",
"{name}2"
],
"type": "integer"
}
}
},
{
"_custom_tl": {
"match": "*_custom_tl",
"mapping": {
"copy_to": [
"all_text",
"{name}2"
],
"type": "long"
}
}
},
{
"_custom_td": {
"match": "*_custom_td",
"mapping": {
"copy_to": [
"all_text",
"{name}2"
],
"type": "double"
}
}
},
{
"_custom_tdt": {
"match": "*_custom_tdt",
"mapping": {
"copy_to": [
"all_text",
"{name}2"
],
"type": "date"
}
}
},
{
"custom_ti2": {
"match": "*_custom_ti2",
"mapping": {
"analyzer": "index_text_en",
"copy_to": "all_text",
"search_analyzer": "search_text",
"store": true,
"type": "text"
}
}
},
{
"custom_tl2": {
"match": "*_custom_tl2",
"mapping": {
"analyzer": "index_text_en",
"copy_to": "all_text",
"search_analyzer": "search_text",
"store": true,
"type": "text"
}
}
},
{
"custom_td2": {
"match": "*_custom_td2",
"mapping": {
"analyzer": "index_text_en",
"copy_to": "all_text",
"search_analyzer": "search_text",
"store": true,
"type": "text"
}
}
}
],
"properties": {
"alert_name": {
"type": "text",
"copy_to": [
"all_text"
],
"analyzer": "index_text_en",
"search_analyzer": "search_text"
},
"alert_xml": {
"type": "text",
"copy_to": [
"all_text"
],
"analyzer": "index_text_html",
"search_analyzer": "search_text"
},
"all_text": {
"type": "text",
"analyzer": "index_text_html",
"search_analyzer": "search_text"
},
"attachment": {
"type": "text",
"analyzer": "index_text_en",
"search_analyzer": "search_text"
},
"audit": {
"type": "text",
"analyzer": "index_text_en",
"search_analyzer": "search_text"
},
"audits": {
"properties": {
"comment": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"date": {
"type": "date"
},
"event": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"user": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
}
}
},
"bu": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"bu_exact": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"bu_name": {
"type": "text",
"copy_to": [
"all_text"
],
"analyzer": "index_text_en",
"search_analyzer": "search_text"
},
"business_date": {
"type": "date",
"copy_to": [
"all_text"
]
},
"category": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"consolidation_key": {
"type": "text",
"copy_to": [
"all_text"
],
"analyzer": "index_text_en",
"search_analyzer": "search_text"
},
"create_date": {
"type": "date",
"copy_to": [
"all_text"
]
},
"description": {
"type": "text",
"copy_to": [
"all_text"
],
"analyzer": "index_text_en",
"search_analyzer": "search_text"
},
"display_name": {
"type": "text",
"copy_to": [
"all_text"
],
"analyzer": "index_text_en",
"search_analyzer": "search_text"
},
"has": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"id": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"identifier": {
"type": "text",
"copy_to": [
"all_text"
],
"analyzer": "identifier_analyzer",
"search_analyzer": "search_text"
},
"is": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"last_update_date": {
"type": "date"
},
"manual": {
"type": "boolean"
},
"module": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"note": {
"type": "text",
"copy_to": [
"all_text"
],
"analyzer": "index_text_en",
"search_analyzer": "search_text"
},
"owner": {
"type": "text",
"copy_to": [
"all_text"
],
"analyzer": "index_text_en",
"search_analyzer": "search_text"
},
"owner_name": {
"type": "text",
"copy_to": [
"all_text"
],
"analyzer": "index_text_en",
"search_analyzer": "search_text"
},
"priority_identifier": {
"type": "text",
"copy_to": [
"all_text"
],
"analyzer": "index_text_en",
"search_analyzer": "search_text"
},
"read": {
"type": "boolean"
},
"reason": {
"type": "text",
"copy_to": [
"all_text"
],
"analyzer": "index_text_en",
"search_analyzer": "search_text"
},
"rfi": {
"type": "text",
"copy_to": [
"all_text"
],
"analyzer": "index_text_en",
"search_analyzer": "search_text"
},
"rfi_attachment": {
"type": "text",
"analyzer": "index_text_en",
"search_analyzer": "search_text"
},
"score_field": {
"type": "long",
"copy_to": [
"all_text",
"score_field2"
]
},
"score_field2": {
"type": "text",
"store": true,
"analyzer": "index_text_en",
"search_analyzer": "search_text"
},
"state": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword"
}
},
"copy_to": [
"all_text"
],
"analyzer": "index_text_en",
"search_analyzer": "search_text"
},
"step": {
"type": "text",
"copy_to": [
"all_text"
],
"analyzer": "index_text_en",
"search_analyzer": "search_text"
},
"tenant": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"type": {
"type": "text",
"copy_to": [
"all_text"
],
"analyzer": "index_text_en",
"search_analyzer": "search_text"
},
"type_abbr_name": {
"type": "text",
"copy_to": [
"all_text"
],
"analyzer": "index_text_en",
"search_analyzer": "search_text"
},
"type_facet": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword"
}
},
"copy_to": [
"all_text"
],
"analyzer": "index_text_en",
"search_analyzer": "search_text"
},
"type_name": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword"
}
},
"copy_to": [
"all_text"
],
"analyzer": "index_text_en",
"search_analyzer": "search_text"
}
}
}
}
}
To summarize the query:
- It searches two fields: (identifier, all_text).
- The "identifier" field is just a short/unique value given to each document.
- The "all_text" field is an aggregate of the values of about 20 field... using the "copy_to" property in the mapping.
- The "attachment" field is the likely troublemaker, because the value can be very large (over 100MB) for some rare documents.
- However, the "attachment" field value is not added to "all_text" in the mapping.
- In the query, the "attachment" field is also excluded from the list of source fields to return.
- The query also omits the "attachment" field from the list of fields to highlight.
I know that having a potentially huge field like this was a poor design decision. But despite this, Elastic seems to behave strangely. In particular, the "HighlightPhase" seems to be processing a field that doesn't needs to be highlighted.