I am not able to figure out how to 2 analyzers on a field. I have the following Index Class defined -
class ConnectorApiIndex(Document):
title = Text(analyzer=[NGRAM_TOKEN_ANALYSER, STANDARD_TOKEN_ANALYZER], search_analyzer=STANDARD_TOKEN_ANALYZER)
description = Text(analyzer=[NGRAM_TOKEN_ANALYSER, STANDARD_TOKEN_ANALYZER], search_analyzer=STANDARD_TOKEN_ANALYZER)
url = Text(analyzer=[NGRAM_TOKEN_ANALYSER, STANDARD_TOKEN_ANALYZER], search_analyzer=STANDARD_TOKEN_ANALYZER)
parent_connector_id = Text()
owner_id = Text()
class Index:
name = settings.SERVER_NAME + '-connector-api-index'
When I check the mapping in the elasticsearch head, in the analysis key I can see two analyzer but on the field there is only one analyzer -
{
"index": {
"number_of_shards": "5",
"provided_name": "pre-dev.kwikui.com-connector-api-index",
"creation_date": "1552045118501",
"analysis": {
"analyzer": {
"standard_token_analyzer": {
"filter": [
"standard",
"lowercase"
],
"type": "custom",
"tokenizer": "standard"
},
"ngram_token_analyser": {
"filter": [
"standard",
"lowercase"
],
"type": "custom",
"tokenizer": "gram"
}
},
"tokenizer": {
"gram": {
"type": "ngram",
"min_gram": "3",
"max_gram": "16"
}
}
},
"number_of_replicas": "1",
"uuid": "YA4hjx9vTIKNq5xUS_WCJQ",
"version": {
"created": "6060099"
}
}
}
{
"mappings": {
"doc": {
"properties": {
"owner_id": {
"type": "text"
},
"description": {
"search_analyzer": "standard_token_analyzer",
"analyzer": "ngram_token_analyser",
"type": "text"
},
"title": {
"search_analyzer": "standard_token_analyzer",
"analyzer": "ngram_token_analyser",
"type": "text"
},
"parent_connector_id": {
"type": "text"
},
"url": {
"search_analyzer": "standard_token_analyzer",
"analyzer": "ngram_token_analyser",
"type": "text"
}
}
}
}
}
@HonzaKral I am not able find anything regarding this in the documentation too, its kind a important for me to figure this out.
If you want to use multiple analyzers you need to define multiple fields:
class ConnectorApiIndex(Document):
title = Text(analyzer=NGRAM_TOKEN_ANALYSER, search_analyzer=STANDARD_TOKEN_ANALYZER, fields={'standard': Text(analyzer=STANDARD_TOKEN_ANALYZER)})
now you can use title and title.standard in your queries.
Hope this helps!
Most helpful comment
If you want to use multiple analyzers you need to define multiple fields:
now you can use
titleandtitle.standardin your queries.Hope this helps!