2017-04-15 51 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" 
     } 
    } 
}' 

这是结果:

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

如果这是Solr的,所有我想做是运行这个简单的查询:thumbnail:"thumbnail1536.png"

有人可以告诉我这里怎么了?

回答

2

精确项不匹配,因为您的文档场thumbnail得到了与standard分析仪分析和存储作为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" 
     } 
    } 
}' 

注:这里.keywordkeyword版本thumbnail领域。

虽然两者都产生相同的结果,但上述查询比以前的查询效率更高。

0

这取决于您的字段如何映射/键入。请参阅弹性搜索网站上的link

请注意,您可以更改映射以更好地满足您的需求。

+0

我真的很陌生。所以我不确定为什么这很重要,因为在Solr中,该查询可以对字符串或文本字段起作用。 –

相关问题