2016-11-28 8 views
0

動作しない私は、定義された次のマッピングを持つフィールドがあります。私は、検索しようとすると弾性検索に電子メールでオートコンプリートを使用すると、

{ 
    "analysis": { 
     "filter": { 
      "email_filter": { 
       "type": "edge_ngram", 
       "min_gram": "3", 
       "max_gram": "255" 
      } 
     }, 
     "analyzer": { 
      "email": { 
       "type": "custom", 
       "filter": [ 
        "lowercase", 
        "email_filter", 
        "unique" 
       ], 
       "tokenizer": "uax_url_email" 
      } 
     } 
    } 
} 

"my_field": { 
    "properties": { 
     "address": { 
      "type": "string", 
      "analyzer": "email", 
      "search_analyzer": "whitespace" 
     } 
    } 
} 

を私の電子メール・アナライザは、次のようになります[email protected]のような電子メールIDの場合

tes、test.xyなどの用語を検索すると機能しません。しかし、 test.xyzまたは[email protected]le.comを検索してもうまくいきます。私は私の電子メールフィルタを使ってトークンを分析しようとしましたが、それは期待どおりにうまくいきます。

Ex。 http://localhost:9200/my_index/_analyze?analyzer=email&[email protected]

叩く私が取得:

{ 
    "tokens": [{ 
     "token": "tes", 
     "start_offset": 0, 
     "end_offset": 20, 
     "type": "word", 
     "position": 0 
    }, { 
     "token": "test", 
     "start_offset": 0, 
     "end_offset": 20, 
     "type": "word", 
     "position": 0 
    }, { 
     "token": "test.", 
     "start_offset": 0, 
     "end_offset": 20, 
     "type": "word", 
     "position": 0 
    }, { 
     "token": "test.x", 
     "start_offset": 0, 
     "end_offset": 20, 
     "type": "word", 
     "position": 0 
    }, { 
     "token": "test.xy", 
     "start_offset": 0, 
     "end_offset": 20, 
     "type": "word", 
     "position": 0 
    }, { 
     "token": "test.xyz", 
     "start_offset": 0, 
     "end_offset": 20, 
     "type": "word", 
     "position": 0 
    }, { 
     "token": "[email protected]", 
     "start_offset": 0, 
     "end_offset": 20, 
     "type": "word", 
     "position": 0 
    }, { 
     "token": "[email protected]", 
     "start_offset": 0, 
     "end_offset": 20, 
     "type": "word", 
     "position": 0 
    }, { 
     "token": "[email protected]", 
     "start_offset": 0, 
     "end_offset": 20, 
     "type": "word", 
     "position": 0 
    }, { 
     "token": "[email protected]", 
     "start_offset": 0, 
     "end_offset": 20, 
     "type": "word", 
     "position": 0 
    }, { 
     "token": "[email protected]", 
     "start_offset": 0, 
     "end_offset": 20, 
     "type": "word", 
     "position": 0 
    }, { 
     "token": "[email protected]", 
     "start_offset": 0, 
     "end_offset": 20, 
     "type": "word", 
     "position": 0 
    }, { 
     "token": "[email protected]", 
     "start_offset": 0, 
     "end_offset": 20, 
     "type": "word", 
     "position": 0 
    }, { 
     "token": "[email protected]", 
     "start_offset": 0, 
     "end_offset": 20, 
     "type": "word", 
     "position": 0 
    }, { 
     "token": "[email protected]", 
     "start_offset": 0, 
     "end_offset": 20, 
     "type": "word", 
     "position": 0 
    }, { 
     "token": "[email protected]", 
     "start_offset": 0, 
     "end_offset": 20, 
     "type": "word", 
     "position": 0 
    }, { 
     "token": "[email protected]", 
     "start_offset": 0, 
     "end_offset": 20, 
     "type": "word", 
     "position": 0 
    }, { 
     "token": "[email protected]", 
     "start_offset": 0, 
     "end_offset": 20, 
     "type": "word", 
     "position": 0 
    }] 
} 

は、だから私は、トークン化が機能することを知っています。しかし、検索中は部分文字列を検索できません。

例: http://localhost:9200/my_index/my_field/_search?q=testを検索すると、結果はヒットしません。私のインデックスの

詳細:

{ 
    "my_index": { 
     "aliases": { 
      "alias_default": {} 
     }, 
     "mappings": { 
      "my_field": { 
       "properties": { 
        "address": { 
         "type": "string", 
         "analyzer": "email", 
         "search_analyzer": "whitespace" 
        }, 
        "boost": { 
         "type": "long" 
        }, 
        "createdat": { 
         "type": "date", 
         "format": "strict_date_optional_time||epoch_millis" 
        }, 
        "instanceid": { 
         "type": "long" 
        }, 
        "isdeleted": { 
         "type": "integer" 
        }, 
        "object": { 
         "type": "string" 
        }, 
        "objecthash": { 
         "type": "string" 
        }, 
        "objectid": { 
         "type": "string" 
        }, 
        "parent": { 
         "type": "short" 
        }, 
        "parentid": { 
         "type": "integer" 
        }, 
        "updatedat": { 
         "type": "date", 
         "format": "strict_date_optional_time||epoch_millis" 
        } 
       } 
      } 
     }, 
     "settings": { 
      "index": { 
       "creation_date": "1480342980403", 
       "number_of_replicas": "1", 
       "max_result_window": "100000", 
       "uuid": "OUuiTma8CA2VNtw9Og", 
       "analysis": { 
        "filter": { 
         "email_filter": { 
          "type": "edge_ngram", 
          "min_gram": "3", 
          "max_gram": "255" 
         }, 
         "autocomplete_filter": { 
          "type": "edge_ngram", 
          "min_gram": "3", 
          "max_gram": "20" 
         } 
        }, 
        "analyzer": { 
         "autocomplete": { 
          "type": "custom", 
          "filter": [ 
           "lowercase", 
           "autocomplete_filter" 
          ], 
          "tokenizer": "standard" 
         }, 
         "email": { 
          "type": "custom", 
          "filter": [ 
           "lowercase", 
           "email_filter", 
           "unique" 
          ], 
          "tokenizer": "uax_url_email" 
         } 
        } 
       }, 
       "number_of_shards": "5", 
       "version": { 
        "created": "2010099" 
       } 
      } 
     }, 
     "warmers": {} 
    } 
} 
+0

検索には「search_analyzer」:「空白」アナライザがあります。それを削除してマッピングをしてください – Backtrack

+0

@Backtrackこれは正しいと私は信じています。 http://stackoverflow.com/a/15932838/1465701を確認してください。私がここに何かを見逃していない限り、これは正しい行動でなければならないと思う。 – nerandell

+2

あなたのマッピングにタイプミスがあります。 'analyser'は' analyzer'を読むべきです – Val

答えて

1

[OK]を、すべてがあなたのクエリを除いて、正しく見えます。

あなたは、単にこのようなクエリでaddressフィールドを指定する必要があり、それが動作します:

http://localhost:9200/my_index/my_field/_search?q=address:test 

あなたはaddressフィールドを指定しない場合、クエリは、検索アナライザ_allフィールド上で動作しますデフォルトではstandardですので、何も見つかりません。

+0

それは働いた。私はこれを答えとして受け入れています。 – nerandell

+0

素晴らしい、嬉しい助けて! – Val