2016-12-13 18 views
2

Elasticsearch query_stringに「@」を単純な文字として認識させるにはどうすればよいですか?Elasticsearchを使用して特殊文字を検索する

POST test/item/_bulk 
{"text": "[email protected]"} 
{"text": "[email protected]"} 
{"text": "[email protected], [email protected]"} 
{"text": "john.doe[at]gmail.com"} 
{"text": "john.doe gmail.com"} 

私は、この検索したい:

GET test/item/_search 
{ 
    "query": 
    { 
     "query_string": 
     { 
      "query": "*@gmail.com", 
      "analyze_wildcard": "true", 
      "allow_leading_wildcard": "true", 
      "default_operator": "AND" 
     } 
    } 
} 

のみ最初三分の一を返すために、私はインデックスを持っていると仮定すると、私はこの文で、いくつかの書類を追加

文書

私はマッピングの3種類試した:私が試した まず -

PUT test 
{ 
    "settings": { 
    "analysis": { 
     "analyzer": { 
     "email_analyzer": { 
      "tokenizer": "email_tokenizer" 
     } 
     }, 
     "tokenizer": { 
     "email_tokenizer": { 
      "type": "uax_url_email" 
     } 
     } 
    } 
    }, 
    "mappings": { 
    "item": { 
     "properties": { 
     "text": { 
      "type": "string", 
      "analyzer": "email_analyzer" 
     } 
     } 
    } 
    } 
} 

を私が試したよりも -

PUT test 
{ 
    "settings": { 
    "analysis": { 
     "analyzer": { 
     "my_analyzer": { 
      "tokenizer": "my_tokenizer" 
     } 
     }, 
     "tokenizer": { 
     "my_tokenizer": { 
      "type": "whitespace" 
     } 
     } 
    } 
    }, 
    "mappings": { 
    "item": { 
     "properties": { 
     "text": { 
      "type": "string", 
      "analyzer": "my_analyzer" 
     } 
     } 
    } 
    } 
} 
をし、私もこの1試さない - の

PUT test 
{ 
    "settings": { 
    "analysis": { 
     "analyzer": { 
     "my_analyzer": { 
      "tokenizer": "my_tokenizer" 
     } 
     }, 
     "tokenizer": { 
     "my_tokenizer": { 
      "type": "whitespace" 
     } 
     } 
    } 
    }, 
    "mappings": { 
    "item": { 
     "properties": { 
     "text": { 
      "type": "string", 
      "index": "not_analyzed" 
     } 
     } 
    } 
    } 
} 

なし上記の作業は、実際にはすべてすべての文書を返しました。 ですがElasticsearchは、「@」を認めることは分析しないようにテキストを置くことによって、これがあなたの最後の設定で作業している他の文字

答えて

1

でないように署名するようになりますアナライザー/トークナイザ/パラメータ:

GET test/item/_search 
{ 
    "query": 
    { 
     "wildcard": 
     { 
      "text": "*@gmail.com*" 
     } 
    } 
} 
分析されていないフィールドを使用している場合、あなたはタームレベルのクエリではなく、フルテキストレベルのクエリを使用する必要があります

https://www.elastic.co/guide/en/elasticsearch/reference/2.3/term-level-queries.html

+0

、私が望んでいたように動作するようです。どうもありがとうございます! – AviadG

関連する問題