0
我希望能夠使用某些特殊字符和術語搜索Elasticsearch上的某些文檔。例如,如果我有以下文件:Elasticsearch:使用哪個分析器來通過特殊字符搜索文檔
"HEY YOU! Thanks for reading this post!"
我希望能夠使用查詢字符串,如:
{
"query": {
"query_string": {
"default_field": "content",
"query": "\"!\""
}
}
}
而且具有以前的文檔作爲結果。但我也希望能夠通過查詢有文件:
{
"query": {
"query_string": {
"default_field": "content",
"query": "hey AND you"
}
}
}
我目前使用的標準分詞器,但我不能查詢的特殊字符,還給我沒有文件。 是否有一個標記器已經爲這種任務定義?我認爲沒有分析領域,但我不會有小寫字母的部分。
編輯:
我創建一個自定義分析:
{
"sw3": {
"settings": {
"index": {
"number_of_shards": "5",
"provided_name": "sw3",
"creation_date": "1493907201172",
"analysis": {
"analyzer": {
"my_analyzer": {
"filter": [
"lowercase"
],
"type": "custom",
"tokenizer": "whitespace"
}
}
},
"number_of_replicas": "1",
"uuid": "e0_9cIFrQWqn-zqYeg0q5g",
"version": {
"created": "5030299"
}
}
}
}
}
但是當我嘗試:
{
"query": {
"query_string": {
"default_field": "content",
"query": ";"
}
}
}
我沒有得到任何結果。所以我試圖做:
{
"query": {
"match": {
"content": ";"
}
}
}
但我仍然沒有任何結果。我試試,看看究竟是什麼的tokeniser:
GET /my_index/_analyze?analyzer=my_analyzer
{
"text": "Hey ; what's up"
}
和查詢的結果是:
{
"tokens": [
{
"token": "hey",
"start_offset": 0,
"end_offset": 3,
"type": "word",
"position": 0
},
{
"token": ";",
"start_offset": 4,
"end_offset": 5,
"type": "word",
"position": 1
},
{
"token": "what's",
"start_offset": 6,
"end_offset": 12,
"type": "word",
"position": 2
},
{
"token": "up",
"start_offset": 13,
"end_offset": 15,
"type": "word",
"position": 3
}
]
}
爲什麼我不能獲取任何文件時tokeniser似乎工作?
我更新了我的問題和答案的結果 – mel