Można również tworzyć niestandardowe tokenizera i używać go w nieruchomości multifields jak w następujące:
PUT test_index
{
"settings": {
"analysis": {
"analyzer": {
"character_analyzer": {
"type": "custom",
"tokenizer": "character_tokenizer"
}
},
"tokenizer": {
"character_tokenizer": {
"type": "nGram",
"min_gram": 1,
"max_gram": 1
}
}
}
},
"mappings": {
"person": {
"properties": {
"name": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword"
},
"words_count": {
"type": "token_count",
"analyzer": "standard"
},
"length": {
"type": "token_count",
"analyzer": "character_analyzer"
}
}
}
}
}
}
}
PUT test_index/person/1
{
"name": "John Smith"
}
PUT test_index/person/2
{
"name": "Rachel Alice Williams"
}
GET test_index/person/_search
{
"query": {
"term": {
"name.length": 10
}
}
}
[dokumentacja dla Elasticsearch 2.1] (https://www.elastic.co/ guide/en/elasticsearch/reference/current/modules-scripting.html) nie wymienia pola '.length', czy to nadal działa? – robinst
Prawdopodobnie, jeśli jawnie włączysz obsługę skryptów, to nadal będzie działać (domyślnie skrypt był wyłączony w wersji 1.4). Używamy raczej skryptów Groovy niż MVEL, więc prawdopodobnie będziesz chciał to sprawdzić. – Phil
http://stackoverflow.com/questions/23023233/elasticsearch-statistical-facet-on-length-of-string-field wspomina, że możesz użyć '" script ":" doc ['body']. Value.length() "' który pracował dla mnie w 1.7.5 – nezda