2016-05-02 11 views
0

に入ったとき:elasticsearchは、私は私のアナライザは、次のように設定している部分の単語

"analyzer": { 
    "edgeNgram_autocomplete": { 
     "type": "custom", 
     "tokenizer": "standard", 
     "filter": ["lowercase", "autocomplete"] 
    },     
    "full_name": { 
     "filter":["standard","lowercase","asciifolding"], 
     "type":"custom", 
     "tokenizer":"standard" 
    } 

マイフィルタ:

"filter": { 
    "autocomplete": { 
     "type": "edgeNGram", 
     "side":"front", 
     "min_gram": 1, 
     "max_gram": 50 
    } 

Nameフィールドアナライザ:一緒にすべての

"textbox": { 
    "_parent": { 
     "type": "document" 
    },    
    "properties": { 
     "text": { 
      "fields": { 
       "text": { 
        "type":"string", 
        "analyzer":"full_name" 
       }, 
       "autocomplete": { 
        "type": "string", 
        "index_analyzer": "edgeNgram_autocomplete", 
        "search_analyzer": "full_name", 
        "analyzer": "full_name" 
       } 
      }, 
      "type":"multi_field" 
     } 
    } 
} 

を入れてdocstoreインデックスのマッピングを構成します:

PUT http://localhost:9200/docstore 
{ 
    "settings": { 
     "analysis": { 
      "analyzer": { 
       "edgeNgram_autocomplete": { 
        "type": "custom", 
        "tokenizer": "standard", 
        "filter": ["lowercase", "autocomplete"] 
       },     
       "full_name": { 
        "filter":["standard","lowercase","asciifolding"], 
        "type":"custom", 
        "tokenizer":"standard" 
       } 
      }, 
      "filter": { 
       "autocomplete": { 
        "type": "edgeNGram", 
        "side":"front", 
        "min_gram": 1, 
        "max_gram": 50 
       }   } 
     } 
    }, 
    "mappings": { 
     "space": { 
      "properties": { 
       "name": { 
        "type": "string", 
        "index": "not_analyzed" 
       } 
      } 
     }, 
     "document": { 
      "_parent": { 
       "type": "space" 
      }, 
      "properties": { 
       "name": { 
        "type": "string", 
        "index": "not_analyzed" 
       } 
      } 
     }, 
     "textbox": { 
      "_parent": { 
       "type": "document" 
      },    
      "properties": { 
       "bbox": { 
        "type": "long" 
       }, 
       "text": { 
        "fields": { 
         "text": { 
          "type":"string", 
          "analyzer":"full_name" 
         }, 
         "autocomplete": { 
          "type": "string", 
          "index_analyzer": "edgeNgram_autocomplete", 
          "search_analyzer": "full_name", 
          "analyzer":"full_name" 
         } 
        }, 
        "type":"multi_field" 
       } 
      } 
     }, 
     "entity": { 
      "_parent": { 
       "type": "document" 
      }, 
      "properties": { 
       "bbox": { 
        "type": "long" 
       }, 
       "name": { 
        "type": "string", 
        "index": "not_analyzed" 
       } 
      } 
     } 
    } 
} 

すべてのドキュメントを保持するためのスペースを追加します。

POST http://localhost:9200/docstore/space 
{ 
    "name": "Space 1" 
} 

mapping

ユーザーが単語入る:proj

これは返す必要があり、すべてのテキストを:

  • SampleProject
  • サンプルプロジェクト
  • プロジェクト名
  • myProjectname
  • firstProjectName
  • 私のプロジェクト名

しかし、それは何も返しません。

マイクエリ:私はprojectで検索する場合は

POST http://localhost:9200/docstore/textbox/_search 
{ 
    "query": { 
     "match": { 
      "text": "proj" 
     } 
    }, 
    "filter": { 
     "has_parent": { 
      "type": "document", 
      "query": { 
       "term": { 
        "name": "1-a1-1001.pdf" 
       } 
      } 
     } 
    } 
} 

、私が取得:

{ "took": 4, 
    "timed_out": false, 
    "_shards": { 
     "total": 5, 
     "successful": 5, 
     "failed": 0 
    }, 
    "hits": { 
     "total": 2, 
     "max_score": 3.0133555, 
     "hits": [ 
      { 
       "_index": "docstore", 
       "_type": "textbox", 
       "_id": "AVRuV2d_f4y6IKuxK35g", 
       "_score": 3.0133555, 
       "_routing": "AVRuVvtLf4y6IKuxK33f", 
       "_parent": "AVRuV2cMf4y6IKuxK33g", 
       "_source": { 
        "bbox": [ 
         8750, 
         5362, 
         9291, 
         5445 
        ], 
        "text": [ 
         "Sample Project" 
        ] 
       } 
      }, 
      { 
       "_index": "docstore", 
       "_type": "textbox", 
       "_id": "AVRuV2d_f4y6IKuxK35Y", 
       "_score": 2.4106843, 
       "_routing": "AVRuVvtLf4y6IKuxK33f", 
       "_parent": "AVRuV2cMf4y6IKuxK33g", 
       "_source": { 
        "bbox": [ 
         8645, 
         5170, 
         9070, 
         5220 
        ], 
        "text": [ 
         "Project Name and Address" 
        ] 
       } 
      } 
     ] 
    } 
} 

はたぶん私のedgengramは、このために適していないのですか? 私が言っている:

side":"front" 

私は違っそれを行うべきか?

誰かが私が間違っていることを知っていますか?

答えて

1

問題がオートコンプリートインデックス・アナライザのフィールド名です。

変更:

"index_analyzer": "edgeNgram_autocomplete" 

へ:

"analyzer": "edgeNgram_autocomplete" 

も(@Andreiステファン)のような検索は、彼の答えであった:

POST http://localhost:9200/docstore/textbox/_search 
{ 
    "query": { 
     "match": { 
      "text.autocomplete": "proj" 
     } 
    } 
} 

そして期待どおりに動作します!

私はちなみにElasticsearch 2.3

上のコンフィギュレーションをテストしている、タイプmulti_fielddeprecatedです。

私は助けてくれることを祈っています:)

+0

Multi_filedは文字列で置き換えることができますか? – Angelina

+0

はい、 'string'に置き換えられます。たとえば、あなたの例では、テキストフィールドは次のようになります: '' text ":{ " type ":" string "、 " analyzer ":" full_name "、 " fields ":{ "オートコンプリート ":{ "type": "string"、 "analyzer": "edgeNgram_autocomplete"、 "search_analyzer": "full_name" } } } –

1

あなたのクエリが実際にtext.autocompleteなくtextで一致するようにしてください:

"query": { 
    "match": { 
     "text.autocomplete": "proj" 
    } 
    } 
+0

私もそれを試しました。それは動作しません:( – Angelina

+0

.... OK、結果を提供する次の実行:curl -XGET http:// localhost:9200/docstore/textbox/_search "-d ' { "クエリ「:{ "一致":{ "テキスト": "プロジェクト" } }、 "フィルタ":{ "HAS_PARENT":{ "タイプ": "文書"、 "クエリ":{ "用語":{ "名前": "1-a1-1001.pdf" }}} }、 "fielddata_fields":[ "text.autocomplete"、 "テキスト"] } ' ' –

+0

それをしなかった何でも – Angelina

関連する問題