2016-10-19 15 views
0

のための単語を分割するために使用されていない私は、インデックス文書のマッピングを以下している(簡体字)ドットがアナライザ

{ 
    "documents": { 
     "mappings": { 
      "document": { 
       "properties": { 
        "filename": { 
         "type": "string", 
         "fields": { 
          "lower_case_sort": { 
           "type": "string", 
           "analyzer": "case_insensitive_sort" 
          }, 
          "raw": { 
           "type": "string", 
           "index": "not_analyzed" 
          } 
         } 
        } 
       } 
      } 
     } 
    } 
} 

私は、このインデックス

{ 
    "_index": "documents", 
    "_type": "document", 
    "_id": "777", 
    "_source": { 
     "filename": "text.txt", 
    } 
} 

に二つの文書を置きます。..

{ 
    "_index": "documents", 
    "_type": "document", 
    "_id": "888", 
    "_source": { 
     "filename": "text 123.txt", 
    } 
} 

"text"に対してquery_stringまたはsimple_query_stringクエリを実行すると、両方のドキュメントを取得することが予想されます。b ack。ファイル名が "text.txt"と "text 123.txt"のために一致する必要があります。私が検索した場合にのみ発見された「test.txtの」または「test.txtの」または「テスト -

http://localhost:9200/defiant/_search?q=text 

しかし、私は名前だけ「テスト123.txt」との文書を見つける「テスト*。」 。??? " - ファイル名にドットを追加する必要があります。 >

{ 
    "_index": "documents", 
    "_type": "document", 
    "_id": "777", 
    "matched": false, 
    "explanation": { 
     "value": 0.0, 
     "description": "Failure to meet condition(s) of required/prohibited clause(s)", 
     "details": [{ 
      "value": 0.0, 
      "description": "no match on required clause (_all:text)", 
      "details": [{ 
       "value": 0.0, 
       "description": "no matching term", 
       "details": [] 
      }] 
     }, { 
      "value": 0.0, 
      "description": "match on required clause, product of:", 
      "details": [{ 
       "value": 0.0, 
       "description": "# clause", 
       "details": [] 
      }, { 
       "value": 0.47650534, 
       "description": "_type:document, product of:", 
       "details": [{ 
        "value": 1.0, 
        "description": "boost", 
        "details": [] 
       }, { 
        "value": 0.47650534, 
        "description": "queryNorm", 
        "details": [] 
       }] 
      }] 
     }] 
    } 
} 

私はマッピングを台無しにしました -

これは私のドキュメントID 777(TEXT.TXT)

curl -XGET 'http://localhost:9200/documents/document/777/_explain' -d '{"query": {"query_string" : {"query" : "text"}}}' 

は反対の結果を説明するのですか?私は、 '。 ...文書がインデックス化された用語の区切りとして解析され

編集:case_insensitive_sortのセッティング

{ 
    "documents": { 
     "settings": { 
      "index": { 
       "creation_date": "1473169458336", 
       "analysis": { 
        "analyzer": { 
         "case_insensitive_sort": { 
          "filter": [ 
           "lowercase" 
          ], 
          "tokenizer": "keyword" 
         } 
        } 
       } 
      } 
     } 
    } 
} 
+0

あなたは 'case_insensitive_sort'の設定(トークナイザ、フィルタ)を提供できますか? – ChintanShah25

+0

元の質問を更新しました。デフォルトのアナライザをクエリに適用する必要があるため、これが適切かどうかは不明です。 "case_insensitive_sort"はfilenameのサブフィールドでのみ使用されます。 Resp。 filename.lower_case_sort。 –

答えて

0

standard analyzer(デフォルト・アナライザ)のこの予想される振る舞い、それはstandard tokenizerを使用し、algorithmをあたりとして以来、 ドットは、分離文字として扱われません。

あなたはanalyze api

curl -XGET 'localhost:9200/_analyze' -d ' 
{ 
    "analyzer" : "standard", 
    "text" : "test.txt" 
}' 

の助けを借りてこれを確認することができ、単一のトークンは

{ 
    "tokens": [ 
    { 
     "token": "test.txt", 
     "start_offset": 0, 
     "end_offset": 8, 
     "type": "<ALPHANUM>", 
     "position": 0 
    } 
    ] 
} 

を生成しているあなたは、空のスペースでドットを置き換えるためにpattern replace char filterを使用することができます。

{ 
    "settings": { 
    "analysis": { 
     "analyzer": { 
     "my_analyzer": { 
      "tokenizer": "standard", 
      "char_filter": [ 
      "replace_dot" 
      ] 
     } 
     }, 
     "char_filter": { 
     "replace_dot": { 
      "type": "pattern_replace", 
      "pattern": "\\.", 
      "replacement": " " 
     } 
     } 
    } 
    } 
} 

あなたはREINDEXするドキュメントを持っているでしょうし、あなたが望む結果を得るでしょう。 Analyze apiは、逆インデックスで文書がどのように格納されているかを確認するのに非常に便利です。

UPDATE

あなたはあなたが検索したいフィールドの名前を指定する必要があります。次の要求は_all fieldを検索します。デフォルトでは標準アナライザーが使用されています。

http://localhost:9200/defiant/_search?q=text 

私は次のクエリはあなたに望ましい結果を与えると思う。

curl -XGET 'http://localhost:9200/twitter/_search?q=filename:text' 
+0

アナライザは機能します。私はカスタムアナライザーを追加しましたが、再インデックスは役に立たなかった。 –

+0

私は新しいインデックスを作成しましたが、そこにはまだ運がありません... "filename":{"type": "string"、 "analyzer": "my_analyzer"}でマッピングを定義しましたが、役に立たないです。私がlocalhost:9200/_analyzeを新しいアナライザーに対して呼び出すと、文字列は完全に分割されます。私はまだ何かが欠けていると思う。 –

+0

私は自分の答えを更新しました。これが動作しない場合私に教えてください – ChintanShah25