2016-10-30 6 views
0

私のデータベースでURLを検索したいのですが。私はこのようなソースを検索すると、私は私の結果を得ることができますなぜこの単純な弾性検索クエリは何も返しませんか?

{ 
     "_index": "test", 
     "_type": "medhelp", 
     "_id": "AVgPTB_dMXsxewkUBUNN", 
     "_score": 1, 
     "_source": { 
      "title": "Pump minimed 404sp, 506,507,508", 
      "text": "", 
      "abstract": "\n   I am looking to buy one of these pump for testing purpose. It need to be in working condition. Email me if you have one for sale ***@****\n  ", 
      "answers": [], 
      "source": "medhelp", 
      "link": "/posts/Diabetes---Type-1/Pump-minimed-404sp--506-507-508/show/2431714" 
     } 

{ 
    "query": { 
     "prefix": { 
      "source": "medhelp" 
     } 
    } 
} 

が、私は「リンク」フィールドに同じことをしようと私はこのような文書を持っていますURLは常に返されるものはありません。これは何と間違っている:

{ 
    "query": { 
     "prefix": { 
      "link": "/posts/Diabetes---Type-1/Pump-minimed-404sp--506-507-508/show/2431714" 
     } 
    } 
} 

そして、このことは上記のクエリの結果である:

{ 
    "took": 5, 
    "timed_out": false, 
    "_shards": { 
     "total": 5, 
     "successful": 5, 
     "failed": 0 
    }, 
    "hits": { 
     "total": 0, 
     "max_score": null, 
     "hits": [] 
    } 
} 

答えて

1

私は「リンク」の値は全体として扱われていないので、あなたはデフォルトの「標準」アナライザを使用すると思いますが、むしろ多くの小さな作品。

答えは "link"フィールドに "keyword" analyzerを使用することです。

どのように達成できるかの例は次のコードにあります(SenseプラグインからChromeブラウザを使用して一度に1つのコードを実行できます)。

最も重要なことは、 "link:"フィールドマッピングの "analyzer:keyword"です。 この行を削除すると、正確にあなたのケースを得るでしょう。

DELETE /test123 
PUT /test123 
{ 
     "mappings": { 
      "medhelp" : { 
       "properties": { 
       "link": { "type": "string" 
       ,"analyzer": "keyword" 
       }, 
       "source": { "type": "string"} 
     } 
    } 
    } 
} 

GET /test123/_mapping 

PUT /test123/medhelp/1 
{ 
    "link":"/posts/Diabetes---Type-1/Pump-minimed-404sp--506-507-508/show/2431714", 
    "source":"medhelp" 
} 

GET /test123/_search 
{ 
    "query": { 
     "prefix": { 
      "link": "/posts/Diabetes---Type-1/Pump-minimed-404sp--506-507-508/show/2431714" 
     } 
    } 
} 
関連する問題