[英]Elasticsearch [filtered] query does not support [suggest]
I want to allow our users to search for objects by text and geo location. 我想允许我们的用户按文本和地理位置搜索对象。 When searching by text though I would like it suggest terms to as you would with a normal query and a completion suggestor.
当我按文本搜索时,我希望它像普通查询和完成建议器一样建议术语。 When I try to add the suggestor to my filtered query I get an error.
当我尝试将建议者添加到过滤的查询中时,出现错误。 Any suggestions?
有什么建议么?
My mapping: 我的映射:
curl -XPUT http://localhost:9200/objects/object/_mapping -d '{
"object": {
"properties": {
"objectDescription": {
"type": "string"
},
"suggest": {
"type": "completion",
"analyzer": "standard",
"search_analyzer": "standard",
"payloads": true
}
}
}
}'
curl -X PUT http://localhost:9200/objects/object/_mapping -d '{
"object":{"properties":{"location":{"type":"geo_point"}}}
}'
My search: 我的搜索:
{
"query": {
"filtered": {
"query": {
"fuzzy": {
"objectDescription": {
"value": "burger"
}
}
},
"filter": {
"or": [
{
"geo_distance": {
"distance": "15mi",
"location": {
"lat": 33.4255104,
"lon": -111.94000540000002
}
}
},
{
"bool": {
"must": [
{
"term": {
"administrative_area_level_1": "AZ"
}
},
{
"term": {
"addressType": "administrative_area_level_1"
}
}
]
}
}
]
}
}
}
}
When I add the suggest at the same level as the query as you would without a filter it ignores my filter. 当我在没有过滤器的情况下将建议添加到与查询相同的级别时,它将忽略我的过滤器。 It will find the object when searched that is no where near the lat lng.
搜索时它将找到位于纬线附近的对象。
{
"query":{
"filtered":{
"query":{
"fuzzy":{
"objectDescription":{"value":"bears"}
}
},
"filter":{
"bool":{
"should":[
{
"geo_distance":{
"distance":"15mi",
"location":{
"lat":43.6187102,
"lon":-116.21460680000001
}
}
},
{
"bool":{
"must":[
{
"term":{"administrative_area_level_1":"ID"}
},{
"term":{"addressType":"administrative_area_level_1"}
}
]
}
}
]
}
}
}
},
"suggest":{
"object-suggest":{
"text":"bears",
"completion":{
"field":"suggest",
"fuzzy":{"fuzziness":2}
}
}
}
}
When I place the suggest portion of the body in place of the query I get this error. 当我将正文的建议部分代替查询时,出现此错误。
{
"query":{
"filtered":{
"suggest":{
"object-suggest":{
"text":"bears",
"completion":{
"field":"suggest",
"fuzzy":{"fuzziness":2}
}
}
},
"filter":{
"bool":{
"should":[
{
"geo_distance":{
"distance":"15mi",
"location":{
"lat":43.6187102,
"lon":-116.21460680000001
}
}
},
{
"bool":{
"must":[
{
"term":{"administrative_area_level_1":"ID"}
},{
"term":{"addressType":"administrative_area_level_1"}
}
]
}
}
]
}
}
}
}
}
So my problem is I haven't found an example on elastic.co or on stackoverflow that has this combination of geolocation searching with a completion suggestor. 所以我的问题是我没有在elastic.co或stackoverflow上找到一个结合了地理位置搜索和完成建议器的示例。
Try like this. 尝试这样。 The
suggest
block goes at the top-level on its own: suggest
块本身位于顶层:
{
"query": {
"filtered": {
"filter": {
"bool": {
"should": [
{
"geo_distance": {
"distance": "15mi",
"location": {
"lat": 43.6187102,
"lon": -116.21460680000001
}
}
},
{
"bool": {
"must": [
{
"term": {
"administrative_area_level_1": "ID"
}
},
{
"term": {
"addressType": "administrative_area_level_1"
}
}
]
}
}
]
}
}
}
},
"suggest": {
"object-suggest": {
"text": "bears",
"completion": {
"field": "suggest",
"fuzzy": {
"fuzziness": 2
}
}
}
}
}
UPDATE 更新
For your precise use case, I think you should use the context suggester with a geo-location context, instead of a simple completion suggester. 对于您的精确用例,我认为您应该将上下文建议器与地理位置上下文一起使用,而不是简单的完成建议器。 That's most certainly what you need in order to achieve what you expect.
这无疑是您实现期望所需要的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.