Versions
- OpenSearch 2.6.0
- OpenSearch Dashboard 2.6.0
Issue:
OpenSearch - Queries with synonyms do not work properly.
When I search for any query (having synonyms within the file), opensearch is not generating query for all the provided fields.
e.g. search query is accounting (having bookkeeping as a synonym) and intro,title_no_stem,keywords_all are search fields. For this, opensearch generated query is
"type": "DisjunctionMaxQuery",
"description": "(Synonym(title_no_stem:accounting title_no_stem:bookkeeping) | Synonym(title_no_stem:accounting title_no_stem:bookkeeping) | Synonym(title_no_stem:accounting title_no_stem:bookkeeping))",
In the above description, intro, keywords_all field queries are missing.
Search Query :
POST /dev_search_index/_search
{
"query": {
"query_string": {
"fields": [
"intro",
"title_no_stem",
"keywords_all"
],
"query": "accounting"
}
},
"_source": false,
"profile": "true",
"explain": false
}
Search Response :
{
"took": 1,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"skipped": 0,
"failed": 0
},
"hits": {
"total": {
"value": 0,
"relation": "eq"
},
"max_score": null,
"hits": []
},
"profile": {
"shards": [
{
"id": "[BAeehVYMSnm-zMwaauAtGw][dev_search_index][0]",
"inbound_network_time_in_millis": 0,
"outbound_network_time_in_millis": 0,
"searches": [
{
"query": [
{
"type": "DisjunctionMaxQuery",
"description": "(Synonym(title_no_stem:accounting title_no_stem:bookkeeping) | Synonym(title_no_stem:accounting title_no_stem:bookkeeping) | Synonym(title_no_stem:accounting title_no_stem:bookkeeping))",
"time_in_nanos": 14987,
"breakdown": {
"set_min_competitive_score_count": 0,
"match_count": 0,
"shallow_advance_count": 0,
"set_min_competitive_score": 0,
"next_doc": 0,
"match": 0,
"next_doc_count": 0,
"score_count": 0,
"compute_max_score_count": 0,
"compute_max_score": 0,
"advance": 0,
"advance_count": 0,
"score": 0,
"build_scorer_count": 0,
"create_weight": 14987,
"shallow_advance": 0,
"create_weight_count": 1,
"build_scorer": 0
},
"children": [
{
"type": "SynonymQuery",
"description": "Synonym(title_no_stem:accounting title_no_stem:bookkeeping)",
"time_in_nanos": 4407,
"breakdown": {
"set_min_competitive_score_count": 0,
"match_count": 0,
"shallow_advance_count": 0,
"set_min_competitive_score": 0,
"next_doc": 0,
"match": 0,
"next_doc_count": 0,
"score_count": 0,
"compute_max_score_count": 0,
"compute_max_score": 0,
"advance": 0,
"advance_count": 0,
"score": 0,
"build_scorer_count": 0,
"create_weight": 4407,
"shallow_advance": 0,
"create_weight_count": 1,
"build_scorer": 0
}
},
{
"type": "SynonymQuery",
"description": "Synonym(title_no_stem:accounting title_no_stem:bookkeeping)",
"time_in_nanos": 648,
"breakdown": {
"set_min_competitive_score_count": 0,
"match_count": 0,
"shallow_advance_count": 0,
"set_min_competitive_score": 0,
"next_doc": 0,
"match": 0,
"next_doc_count": 0,
"score_count": 0,
"compute_max_score_count": 0,
"compute_max_score": 0,
"advance": 0,
"advance_count": 0,
"score": 0,
"build_scorer_count": 0,
"create_weight": 648,
"shallow_advance": 0,
"create_weight_count": 1,
"build_scorer": 0
}
},
{
"type": "SynonymQuery",
"description": "Synonym(title_no_stem:accounting title_no_stem:bookkeeping)",
"time_in_nanos": 367,
"breakdown": {
"set_min_competitive_score_count": 0,
"match_count": 0,
"shallow_advance_count": 0,
"set_min_competitive_score": 0,
"next_doc": 0,
"match": 0,
"next_doc_count": 0,
"score_count": 0,
"compute_max_score_count": 0,
"compute_max_score": 0,
"advance": 0,
"advance_count": 0,
"score": 0,
"build_scorer_count": 0,
"create_weight": 367,
"shallow_advance": 0,
"create_weight_count": 1,
"build_scorer": 0
}
}
]
}
],
"rewrite_time": 33879,
"collector": [
{
"name": "SimpleTopScoreDocCollector",
"reason": "search_top_hits",
"time_in_nanos": 1972
}
]
}
],
"aggregations": []
}
]
}
}
Configuration:
Index Mapping:
{
"mappings": {
"properties": {
"title": {
"analyzer": "text_general_classic_analyzer",
"copy_to": [
"title_no_stem"
],
"index": "true",
"search_analyzer": "text_general_classic_search_analyzer",
"store": "true",
"term_vector": "with_positions_offsets",
"type": "text"
},
"title_no_stem": {
"analyzer": "text_general_exact_analyzer",
"index": "true",
"search_analyzer": "text_general_exact_search_analyzer",
"store": "false",
"term_vector": "with_positions_offsets",
"type": "text"
},
"keywords_all": {
"analyzer": "text_general_classic_analyzer",
"copy_to": "spellcheck_field",
"index": "true",
"search_analyzer": "text_general_classic_search_analyzer",
"store": "true",
"term_vector": "with_positions_offsets",
"type": "text"
},
"intro": {
"analyzer": "text_general_classic_analyzer",
"search_analyzer": "text_general_classic_search_analyzer",
"index": "true",
"store": "true",
"copy_to": [
"spellcheck_field",
"_text_",
"_all_tokens_",
"suggest_fields"
],
"term_vector": "with_positions_offsets",
"type": "text"
}
}
},
"settings": {
"index.mapping.total_fields.limit": 3000,
"analysis": {
"analyzer": {
"text_general_classic_analyzer": {
"filter": [
"word_delimiter_graph_filter",
"flatten_graph",
"stop_false_filter",
"lowercase",
"remove_duplicates"
],
"tokenizer": "whitespace",
"type": "custom"
},
"text_general_classic_search_analyzer": {
"filter": [
"synonym_filter",
"word_delimiter_graph_filter",
"flatten_graph",
"stop_false_filter",
"lowercase",
"remove_duplicates"
],
"tokenizer": "whitespace",
"type": "custom"
},
"text_general_exact_analyzer": {
"filter": [
"word_delimiter_graph_filter",
"flatten_graph",
"stop_false_filter",
"lowercase",
"remove_duplicates"
],
"tokenizer": "whitespace",
"type": "custom"
},
"text_general_exact_search_analyzer": {
"filter": [
"synonym_filter",
"word_delimiter_graph_filter",
"flatten_graph",
"stop_false_filter",
"lowercase",
"remove_duplicates"
],
"tokenizer": "whitespace",
"type": "custom"
}
},
"filter": {
"synonym_filter": {
"expand": "true",
"synonyms_path": "dev_index/synonyms.txt",
"type": "synonym",
"lenient": true
},
"word_delimiter_graph_filter": {
"catenateAll": "0",
"catenateNumbers": "0",
"catenateWords": "0",
"generateNumberParts": "0",
"generateWordParts": "0",
"type": "word_delimiter_graph"
},
"stop_filter": {
"ignore_case": true,
"type": "stop",
"stopwords_path": "dev_index/stopwords.txt"
},
"stop_false_filter": {
"ignore_case": false,
"type": "stop",
"stopwords_path": "dev_index/stopwords.txt"
}
},
"tokenizer": {}
}
}
}
synonyms.txt
accounting, bookkeeping
compensation,pay,salary,income
computer,pc
Other resource files like stopwords.txt, protwords.txt and stemdict.txt are with sample words.
Screenshots: