Last active
April 14, 2021 06:25
-
-
Save dainiusjocas/bf54cfb955a1e378c477063735e3611e to your computer and use it in GitHub Desktop.
Elasticsearch multiplexer token filter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
PUT /multiplexer_example | |
{ | |
"settings": { | |
"analysis": { | |
"analyzer": { | |
"my_analyzer": { | |
"tokenizer": "standard", | |
"filter": [ "my_multiplexer" ] | |
} | |
}, | |
"filter": { | |
"my_multiplexer": { | |
"type": "multiplexer", | |
"filters": [ "lowercase", "lowercase, porter_stem" ] | |
} | |
} | |
} | |
}, | |
"mappings": { | |
"properties": { | |
"title": { | |
"type": "text", | |
"analyzer": "my_analyzer" | |
} | |
} | |
} | |
} | |
POST /multiplexer_example/_analyze | |
{ | |
"analyzer" : "my_analyzer", | |
"text" : "The quick brown foxes jumps over the lazy dogs" | |
} | |
PUT multiplexer_example/_doc/1 | |
{ | |
"title": "The quick brown foxes jump over the lazy dogs" | |
} | |
PUT multiplexer_example/_doc/2 | |
{ | |
"title": "The quick brown fox jumps over the lazy dog" | |
} | |
# Get all non stemmed | |
GET multiplexer_example/_search | |
{ | |
"highlight": { | |
"fields": { | |
"title": {} | |
} | |
}, | |
"query": { | |
"match": { | |
"title": { | |
"query": "Quick foxes jump", | |
"analyzer": "simple" | |
} | |
} | |
} | |
} | |
# output | |
{ | |
"took" : 2, | |
"timed_out" : false, | |
"_shards" : { | |
"total" : 1, | |
"successful" : 1, | |
"skipped" : 0, | |
"failed" : 0 | |
}, | |
"hits" : { | |
"total" : { | |
"value" : 2, | |
"relation" : "eq" | |
}, | |
"max_score" : 1.1946297, | |
"hits" : [ | |
{ | |
"_index" : "multiplexer_example", | |
"_type" : "_doc", | |
"_id" : "1", | |
"_score" : 1.1946297, | |
"_source" : { | |
"title" : "The quick brown foxes jump over the lazy dogs" | |
}, | |
"highlight" : { | |
"title" : [ | |
"The <em>quick</em> brown <em>foxes</em> <em>jump</em> over the lazy dogs" | |
] | |
} | |
}, | |
{ | |
"_index" : "multiplexer_example", | |
"_type" : "_doc", | |
"_id" : "2", | |
"_score" : 0.41181463, | |
"_source" : { | |
"title" : "The quick brown fox jumps over the lazy dog" | |
}, | |
"highlight" : { | |
"title" : [ | |
"The <em>quick</em> brown fox <em>jumps</em> over the lazy dog" | |
] | |
} | |
} | |
] | |
} | |
} | |
GET multiplexer_example/_search | |
{ | |
"highlight": { | |
"fields": { | |
"title": {} | |
} | |
}, | |
"query": { | |
"match": { | |
"title": { | |
"query": "Quick foxes jump", | |
"analyzer": "english" | |
} | |
} | |
} | |
} | |
# outputs | |
{ | |
"took" : 3, | |
"timed_out" : false, | |
"_shards" : { | |
"total" : 1, | |
"successful" : 1, | |
"skipped" : 0, | |
"failed" : 0 | |
}, | |
"hits" : { | |
"total" : { | |
"value" : 2, | |
"relation" : "eq" | |
}, | |
"max_score" : 0.6177219, | |
"hits" : [ | |
{ | |
"_index" : "multiplexer_example", | |
"_type" : "_doc", | |
"_id" : "1", | |
"_score" : 0.6177219, | |
"_source" : { | |
"title" : "The quick brown foxes jump over the lazy dogs" | |
}, | |
"highlight" : { | |
"title" : [ | |
"The <em>quick</em> brown <em>foxes</em> <em>jump</em> over the lazy dogs" | |
] | |
} | |
}, | |
{ | |
"_index" : "multiplexer_example", | |
"_type" : "_doc", | |
"_id" : "2", | |
"_score" : 0.6177219, | |
"_source" : { | |
"title" : "The quick brown fox jumps over the lazy dog" | |
}, | |
"highlight" : { | |
"title" : [ | |
"The <em>quick</em> brown <em>fox</em> <em>jumps</em> over the lazy dog" | |
] | |
} | |
} | |
] | |
} | |
} | |
# Phrase queries | |
GET multiplexer_example/_search | |
{ | |
"highlight": { | |
"fields": { | |
"title": {} | |
} | |
}, | |
"query": { | |
"match_phrase": { | |
"title": { | |
"query": "brown foxes", | |
"analyzer": "simple" | |
} | |
} | |
} | |
} | |
{ | |
"took" : 10, | |
"timed_out" : false, | |
"_shards" : { | |
"total" : 1, | |
"successful" : 1, | |
"skipped" : 0, | |
"failed" : 0 | |
}, | |
"hits" : { | |
"total" : { | |
"value" : 1, | |
"relation" : "eq" | |
}, | |
"max_score" : 0.9887224, | |
"hits" : [ | |
{ | |
"_index" : "multiplexer_example", | |
"_type" : "_doc", | |
"_id" : "1", | |
"_score" : 0.9887224, | |
"_source" : { | |
"title" : "The quick brown foxes jump over the lazy dogs" | |
}, | |
"highlight" : { | |
"title" : [ | |
"The quick <em>brown</em> <em>foxes</em> jump over the lazy dogs" | |
] | |
} | |
} | |
] | |
} | |
} | |
GET multiplexer_example/_search | |
{ | |
"highlight": { | |
"fields": { | |
"title": {} | |
} | |
}, | |
"query": { | |
"match_phrase": { | |
"title": { | |
"query": "brown foxes", | |
"analyzer": "english" | |
} | |
} | |
} | |
} | |
{ | |
"took" : 4, | |
"timed_out" : false, | |
"_shards" : { | |
"total" : 1, | |
"successful" : 1, | |
"skipped" : 0, | |
"failed" : 0 | |
}, | |
"hits" : { | |
"total" : { | |
"value" : 2, | |
"relation" : "eq" | |
}, | |
"max_score" : 0.41181463, | |
"hits" : [ | |
{ | |
"_index" : "multiplexer_example", | |
"_type" : "_doc", | |
"_id" : "1", | |
"_score" : 0.41181463, | |
"_source" : { | |
"title" : "The quick brown foxes jump over the lazy dogs" | |
}, | |
"highlight" : { | |
"title" : [ | |
"The quick <em>brown</em> <em>foxes</em> jump over the lazy dogs" | |
] | |
} | |
}, | |
{ | |
"_index" : "multiplexer_example", | |
"_type" : "_doc", | |
"_id" : "2", | |
"_score" : 0.41181463, | |
"_source" : { | |
"title" : "The quick brown fox jumps over the lazy dog" | |
}, | |
"highlight" : { | |
"title" : [ | |
"The quick <em>brown</em> <em>fox</em> jumps over the lazy dog" | |
] | |
} | |
} | |
] | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment