-
-
Save dzhlobo/5899923 to your computer and use it in GitHub Desktop.
Tune analyzing process
This file contains hidden or 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
$ cat test_index.json | |
{ | |
"settings": { | |
"number_of_shards": 1, | |
"analysis": { | |
"analyzer": { | |
"titleAnalyzer": { | |
"tokenizer": "titleTokenizer", | |
"filter": ["lowercase"] | |
} | |
}, | |
"tokenizer": { | |
"titleTokenizer": { | |
"type": "nGram", | |
"min_gram": 2, | |
"max_gram": 10, | |
"token_chars": [ "letter", "digit", "symbol" ] | |
} | |
} | |
} | |
}, | |
"mappings": { | |
"movie": { | |
"properties": { | |
"title": { | |
"type": "string", | |
"analyzer": "titleAnalyzer" | |
} | |
} | |
} | |
} | |
} | |
$ http PUT localhost:9200/movies @test_index.json | |
HTTP/1.1 200 OK | |
Content-Length: 606 | |
Content-Type: application/json; charset=UTF-8 | |
{ | |
"movies": { | |
"settings": { | |
"index.analysis.analyzer.titleAnalyzer.filter.0": "lowercase", | |
"index.analysis.analyzer.titleAnalyzer.tokenizer": "titleTokenizer", | |
"index.analysis.tokenizer.titleTokenizer.max_gram": "10", | |
"index.analysis.tokenizer.titleTokenizer.min_gram": "2", | |
"index.analysis.tokenizer.titleTokenizer.token_chars.0": "letter", | |
"index.analysis.tokenizer.titleTokenizer.token_chars.1": "digit", | |
"index.analysis.tokenizer.titleTokenizer.token_chars.2": "symbol", | |
"index.analysis.tokenizer.titleTokenizer.type": "nGram", | |
"index.number_of_replicas": "1", | |
"index.number_of_shards": "1", | |
"index.version.created": "200699" | |
} | |
} | |
} | |
$ http localhost:9200/movies/_mapping | |
HTTP/1.1 200 OK | |
Content-Length: 90 | |
Content-Type: application/json; charset=UTF-8 | |
{ | |
"movies": { | |
"movie": { | |
"properties": { | |
"title": { | |
"analyzer": "titleAnalyzer", | |
"type": "string" | |
} | |
} | |
} | |
} | |
} | |
$ cat doc1.json | |
{ | |
"title": "3:10 to Yuma", | |
"length": 90 | |
} | |
$ cat doc2.json | |
{ | |
"title": "Carnival Story", | |
"length": 100 | |
} | |
$ http POST localhost:9200/movies/movie/1 @doc1.json | |
HTTP/1.1 201 Created | |
Content-Length: 68 | |
Content-Type: application/json; charset=UTF-8 | |
{ | |
"_id": "1", | |
"_index": "movies", | |
"_type": "movie", | |
"_version": 1, | |
"ok": true | |
} | |
$ http POST localhost:9200/movies/movie/2 @doc2.json | |
HTTP/1.1 201 Created | |
Content-Length: 68 | |
Content-Type: application/json; charset=UTF-8 | |
{ | |
"_id": "2", | |
"_index": "movies", | |
"_type": "movie", | |
"_version": 1, | |
"ok": true | |
} | |
$ http http://localhost:9200/movies/_search\?q\="title:3\10" | |
HTTP/1.1 200 OK | |
Content-Length: 255 | |
Content-Type: application/json; charset=UTF-8 | |
{ | |
"_shards": { | |
"failed": 0, | |
"successful": 1, | |
"total": 1 | |
}, | |
"hits": { | |
"hits": [ | |
{ | |
"_id": "1", | |
"_index": "movies", | |
"_score": 0.016057152, | |
"_source": { | |
"length": 90, | |
"title": "3:10 to Yuma" | |
}, | |
"_type": "movie" | |
} | |
], | |
"max_score": 0.016057152, | |
"total": 1 | |
}, | |
"timed_out": false, | |
"took": 102 | |
} | |
$ http http://localhost:9200/movies/_search\?q\="title:carnival" | |
HTTP/1.1 200 OK | |
Content-Length: 240 | |
Content-Type: application/json; charset=UTF-8 | |
{ | |
"_shards": { | |
"failed": 0, | |
"successful": 1, | |
"total": 1 | |
}, | |
"hits": { | |
"hits": [ | |
{ | |
"_id": "2", | |
"_index": "movies", | |
"_score": 0.5, | |
"_source": { | |
"length": 100, | |
"title": "Carnival Story" | |
}, | |
"_type": "movie" | |
} | |
], | |
"max_score": 0.5, | |
"total": 1 | |
}, | |
"timed_out": false, | |
"took": 1 | |
} | |
$ http http://localhost:9200/movies/_search\?q\="title:yuma" | |
HTTP/1.1 200 OK | |
Content-Length: 251 | |
Content-Type: application/json; charset=UTF-8 | |
{ | |
"_shards": { | |
"failed": 0, | |
"successful": 1, | |
"total": 1 | |
}, | |
"hits": { | |
"hits": [ | |
{ | |
"_id": "1", | |
"_index": "movies", | |
"_score": 0.30618626, | |
"_source": { | |
"length": 90, | |
"title": "3:10 to Yuma" | |
}, | |
"_type": "movie" | |
} | |
], | |
"max_score": 0.30618626, | |
"total": 1 | |
}, | |
"timed_out": false, | |
"took": 1 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment