我正在尝试使用snowball分析器对索引进行查询。它似乎不能正常工作。如果我输入"starbuck“,它将返回0个结果,但如果我输入”starbuck“,它将返回名称中包含”starbuck“的所有数据。
我知道,在执行常规搜索时,必须显式指定字段才能使用search_analyzer。
_mapping说我在使用snowball index_analyzer却没有提到snowball search_analyzer,这是不是很奇怪?
映射代码段:
name: {
type: "string",
search_analyzer : "snowball",
index_analyzer : "snowball",
boost : 1
},
tags: {
type: "string",
search_analyzer : "snowball",
index_analyzer : "snowball",
boost : 4
}/business/business/_mapping中的代码片段
name: {type: "string",analyzer: "snowball"},
tags: {type: "string",boost: 4,analyzer: "snowball"}执行搜索的Java代码:
val response = client.prepareSearch("businesses")
.setSearchType(SearchType.DFS_QUERY_THEN_FETCH)
.setQuery(termQuery("name", term))
.setFrom(0).setSize(100).setExplain(true)
.execute()
.actionGet();发布于 2012-12-06 08:33:31
termQuery中指定的术语未按原样进行分析和使用。由于单词Starbucks被索引为术语starbuck,因此您可以返回一些结果。当您搜索术语Starbucks时,索引中没有这样的术语,也得不到任何结果。我建议使用text query,它将对您的术语进行分析。
val response = client.prepareSearch("businesses")
.setSearchType(SearchType.DFS_QUERY_THEN_FETCH)
.setQuery(text("name", term))
.setFrom(0).setSize(100).setExplain(true)
.execute()
.actionGet();发布于 2012-12-06 23:50:02
我还通过执行multi_match查询解决了这个问题。这似乎正确地加强了搜索分析器。
val customQuery = customScoreQuery(
filteredQuery(
multiMatchQuery("Gamestop".toLowerCase())
.field("tags")
.field("name"),
geoDistanceFilter("location")
.point(40.76405282025, -73.972994269042)
.distance(10, DistanceUnit.KILOMETERS)
)
)
.script("customscript")
.lang("native")
.param("lat",40.76405282025)
.param("lon",-73.972994269042)
val response = client.prepareSearch("businesses")
.setSearchType(SearchType.QUERY_AND_FETCH)
.setQuery(customQuery)
.setFrom(0).setSize(100).setExplain(true)
.execute()
.actionGet();这也是使用geodistance过滤器将自定义分数查询与过滤的多匹配查询相结合的一个很好的示例。
https://stackoverflow.com/questions/13729973
复制相似问题