Simple Query String analyzer question

I have created the following index settings and mapping . I used the simple query string syntax for search .
Do I need to explicitly specify my custom analyzer in the simple query search or it uses the required analyzer based on the mapping .

{
"settings": {
"analysis": {
"analyzer": {
"generic_description_analyzer": {
"type": "custom",
"tokenizer": "icu_tokenizer",
"filter": [
"b_synonym",
"lowercase",
"word_split",
"icu_folding",
"english_stop",
"char_replace"
]
}
},
"filter": {
"english_stop": {
"type": "stop",
"stopwords": "english"
},
"word_split": {
"type": "word_delimiter",
"preserve_original": 1
},
"char_replace": {
"type": "pattern_replace",
"pattern": "'",
"replacement": ""
},
"b_synonym": {
"type": "synonym",
"ignore_case": true,
"synonyms_path": "analysis/brand_synonym.txt"
}
}
}
},
"mappings": {
"brands": {
"properties": {
"brand": {
"type": "text",
"analyzer": "generic_description_analyzer"
},
"localbrand": {
"type": "text",
"analyzer": "generic_description_analyzer"
},
"globalbrandextension": {
"type": "text",
"analyzer": "generic_description_analyzer"
},
"productidentifier": {
"type": "text",
"analyzer": "generic_description_analyzer"
},
"category": {
"type": "text",
"analyzer": "generic_description_analyzer"
}
}
}
}
}

Query 1:
{
"query": {
"simple_query_string" : {
"query": "+(|Foster's|Foster's Lager|Foster's Lager Beer)+",
"fields": ["brand", "globalbrandextension", "localbrand", "productidentifier"],
"default_operator": "OR"

}
}
}

Query 2
{
"query": {
"simple_query_string" : {
"query": "+(|Foster's|Foster's Lager|Foster's Lager Beer)+",
"fields": ["brand", "globalbrandextension", "localbrand", "productidentifier"],
"default_operator": "OR",
"analyzer": "generic_description_analyzer"
}
}
}

Which query is correct ?

Also how do I run analyze for the simple query string ?

I tried this Is this correct way of analyzing ? I want to see all the tokens.

GET /indexname/_analyze
{
"field": "brand",
"explain": true,
"text": ["|Foster's|Foster's Lager|Foster's Lager Beer"]

}

Hey,

if you query more than one field, you have to test the API against all the fields. Using a dedicated analyzer in your query is not needed, if the analyzer is configured in the mapping already. The _analyze API always works against analyzers, if you want to check out, how your query was fired with all the fields involved, you can use the explain field in a search request to find out how the score was computed and how your query was depicted https://www.elastic.co/guide/en/elasticsearch/reference/5.2/search-request-explain.html

Also, this might be interested for the analyze API https://www.elastic.co/guide/en/elasticsearch/reference/5.2/_explain_analyze.html

hope this helps!

--Alex

Thanks for your reply

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.