2017-04-15 8 views
0

いくつかの結果を表示するために空のクエリを実行すると、そこに値があることがわかります。例:私はこのようなクエリを実行するとElasticSearchは文字列フィールドに存在する正確な値を見つけることができません

{ 
    "took": 6, 
    "timed_out": false, 
    "_shards": { 
     "total": 5, 
     "successful": 5, 
     "failed": 0 
    }, 
    "hits": { 
     "total": 3024, 
     "max_score": 1.0, 
     "hits": [{ 
      "_index": "geotiff_test", 
      "_type": "geometa", 
      "_id": "AVtt5-j6uVuoyTMhX204", 
      "_score": 1.0, 
      "_source": { 
       "thumbnail": "thumbnail1029.png" 
      } 
     }, { 
      "_index": "geotiff_test", 
      "_type": "geometa", 
      "_id": "AVtt5-mTuVuoyTMhX205", 
      "_score": 1.0, 
      "_source": { 
       "thumbnail": "thumbnail1321.png" 
      } 
     }, { 
      "_index": "geotiff_test", 
      "_type": "geometa", 
      "_id": "AVtt5-xkuVuoyTMhX209", 
      "_score": 1.0, 
      "_source": { 
       "thumbnail": "thumbnail2567.png" 
      } 
     }, { 
      "_index": "geotiff_test", 
      "_type": "geometa", 
      "_id": "AVtt5zr8uVuoyTMhX20F", 
      "_score": 1.0, 
      "_source": { 
       "thumbnail": "thumbnail2122.png" 
      } 
     }, { 
      "_index": "geotiff_test", 
      "_type": "geometa", 
      "_id": "AVtt5z23uVuoyTMhX20L", 
      "_score": 1.0, 
      "_source": { 
       "thumbnail": "thumbnail1823.png" 
      } 
     }, { 
      "_index": "geotiff_test", 
      "_type": "geometa", 
      "_id": "AVtt5-53uVuoyTMhX21A", 
      "_score": 1.0, 
      "_source": { 
       "thumbnail": "thumbnail1616.png" 
      } 
     }, { 
      "_index": "geotiff_test", 
      "_type": "geometa", 
      "_id": "AVtt5_AXuVuoyTMhX21C", 
      "_score": 1.0, 
      "_source": { 
       "thumbnail": "thumbnail3002.png" 
      } 
     }, { 
      "_index": "geotiff_test", 
      "_type": "geometa", 
      "_id": "AVtt5_j3uVuoyTMhX21U", 
      "_score": 1.0, 
      "_source": { 
       "thumbnail": "thumbnail3039.png" 
      } 
     }, { 
      "_index": "geotiff_test", 
      "_type": "geometa", 
      "_id": "AVtt5_yQuVuoyTMhX21d", 
      "_score": 1.0, 
      "_source": { 
       "thumbnail": "thumbnail1136.png" 
      } 
     }, { 
      "_index": "geotiff_test", 
      "_type": "geometa", 
      "_id": "AVtt5zbquVuoyTMhX20C", 
      "_score": 1.0, 
      "_source": { 
       "thumbnail": "thumbnail166.png" 
      } 
     }, { 
      "_index": "geotiff_test", 
      "_type": "geometa", 
      "_id": "AVtt5zfsuVuoyTMhX20E", 
      "_score": 1.0, 
      "_source": { 
       "thumbnail": "thumbnail2767.png" 
      } 
     }, { 
      "_index": "geotiff_test", 
      "_type": "geometa", 
      "_id": "AVtt59jQuVuoyTMhX20p", 
      "_score": 1.0, 
      "_source": { 
       "thumbnail": "thumbnail2852.png" 
      } 
     }, { 
      "_index": "geotiff_test", 
      "_type": "geometa", 
      "_id": "AVtt5_PpuVuoyTMhX21J", 
      "_score": 1.0, 
      "_source": { 
       "thumbnail": "thumbnail1392.png" 
      } 
     }, { 
      "_index": "geotiff_test", 
      "_type": "geometa", 
      "_id": "AVtt58YguVuoyTMhX20N", 
      "_score": 1.0, 
      "_source": { 
       "thumbnail": "thumbnail603.png" 
      } 
     }, { 
      "_index": "geotiff_test", 
      "_type": "geometa", 
      "_id": "AVtt5_38uVuoyTMhX21h", 
      "_score": 1.0, 
      "_source": { 
       "thumbnail": "thumbnail416.png" 
      } 
     }, { 
      "_index": "geotiff_test", 
      "_type": "geometa", 
      "_id": "AVtt5-JFuVuoyTMhX20y", 
      "_score": 1.0, 
      "_source": { 
       "thumbnail": "thumbnail896.png" 
      } 
     }, { 
      "_index": "geotiff_test", 
      "_type": "geometa", 
      "_id": "AVtt6B1NuVuoyTMhX22i", 
      "_score": 1.0, 
      "_source": { 
       "thumbnail": "thumbnail846.png" 
      } 
     }, { 
      "_index": "geotiff_test", 
      "_type": "geometa", 
      "_id": "AVtt6B3vuVuoyTMhX22k", 
      "_score": 1.0, 
      "_source": { 
       "thumbnail": "thumbnail1214.png" 
      } 
     }, { 
      "_index": "geotiff_test", 
      "_type": "geometa", 
      "_id": "AVtt6B90uVuoyTMhX22o", 
      "_score": 1.0, 
      "_source": { 
       "thumbnail": "thumbnail1536.png" 
      } 
     }, { 
      "_index": "geotiff_test", 
      "_type": "geometa", 
      "_id": "AVtt6COkuVuoyTMhX22y", 
      "_score": 1.0, 
      "_source": { 
       "thumbnail": "thumbnail246.png" 
      } 
     }] 
    } 
} 

しかし、それは何も返さない:

curl -X POST http://localhost:9200/geotiff_test/geometa/_search -d '{ 
    "query": { 
     "term": { 
      "thumbnail": "thumbnail1536.png" 
     } 
    } 
}' 

これが結果です:これはSolrのだったら、私がしたいすべての

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

doはこの簡単なクエリを実行します:thumbnail:"thumbnail1536.png"

誰かが私にここで何がうまくいかないと教えてくれる?

答えて

2

文書フィールドthumbnailstandardアナライザで解析され、thumbnail1536pngという名前で保存されているため、正確な用語が一致しません。 Elasticsearchで

text全文)とkeyword正確項)に対して異なるクエリが存在します。あなたが書いたものは後者のカテゴリの下にあります。

あなたがfull-textクエリを実行すると、次の希望を取得します結果:

curl -X POST http://localhost:9200/geotiff_test/geometa/_search -d '{ 
    "query": { 
     "match": { 
      "thumbnail": "thumbnail1536.png" 
     } 
    } 
}' 

しかし、あなたはtermクエリが好ましい使っexact-termを検索しようとしているよう。

curl -X POST http://localhost:9200/geotiff_test/geometa/_search -d '{ 
    "query": { 
     "term": { 
      "thumbnail.keyword": "thumbnail1536.png" 
     } 
    } 
}' 

注:ここでは.keywordthumbnailフィールドのkeywordバージョンです。

どちらも同じ結果が得られますが、上記のクエリは以前のクエリよりも効率的です。

0

フィールドのマッピング/入力方法によって異なります。弾性の検索サイトからこのlinkを参照してください。

必要に応じてマッピングを変更することができます。

+0

私はESが本当に新しいです。だから私はSolrではクエリが文字列またはテキストフィールドのどちらかに対して機能するため、なぜそれが重要なのかわからない。 –

関連する問題