2014-09-19 57 views
4

我试图从多字段获取建议。我找不到像这样的例子,所以也许这不是最好的想法,但我对你的意见感兴趣。elasticsearch完成建议在多字段

映射:

 
POST /authors 
    { 
     "mappings": { 
      "author": { 
      "properties": { 
       "name": { 
        "type": "multi_field", 
        "fields": { 
         "name": { 
         "type": "string", 
         "index": "analyzed" 
         }, 
         "ac": { 
         "type": "completion", 
         "index_analyzer": "simple", 
         "search_analyzer": "simple", 
         "payloads": true 
         } 
        } 
       } 
      } 
      } 
     } 
    } 

数据:

 

POST /authors/author/1 
    { 
     "name": "Fyodor Dostoevsky" 
    } 

查询:

 
POST /authors/_suggest 

    { 
     "authorsAutocomplete": { 
      "text": "fyodor", 
      "completion": { 
      "field": "name.ac" 
      } 
     } 
    } 

的要求是:

  • GET查询与文本“陀”,并与“陀思妥耶夫斯基”的作品,这个例子仅适用于“陀”
  • 可以使过滤建议

任何想法如何,我可以做到这些?

+0

从映射中删除index_analyzer和search_analyzer。保持它只有完成类型.. – 2014-09-19 14:27:18

+0

,没有改变结果 – Ins 2014-10-17 08:22:03

回答

2

首先,建议者在多领域工作不好,所以你可能想把它放在外面。 其次,为了使用名称和名字查询工作,必须在发布数据时选择输出/输入。

工作代码SENSE的例子:

POST authors 

PUT authors/_mapping/author 
{ 
    "properties" : { 
     "name" : { "type" : "string" }, 
     "suggest" : { "type" : "completion"} 
    } 
} 

POST authors/author/1 
{ 
    "name": "Fyodor Dostoevsky", 
    "suggest": { 
     "input": ["Dostoevsky", "Fyodor"], 
     "output": "Fyodor Dostoevsky" 
    } 
} 

POST authors/_suggest 
{ 
    "authorsAutocomplete": { 
     "text": "d", 
     "completion": { 
      "field": "suggest" 
     } 
    } 
} 

DELETE authors 

结果:

{ 
    "_shards": { 
     "total": 5, 
     "successful": 5, 
     "failed": 0 
    }, 
    "authorsAutocomplete": [ 
     { 
      "text": "d", 
      "offset": 0, 
      "length": 1, 
      "options": [ 
       { 
        "text": "Fyodor Dostoevsky", 
        "score": 1 
       } 
      ] 
     } 
    ] 
} 

筛选不可用于建议。要实施某种过滤,您可以查看此建议中关于上下文使用的blog post

+0

谢谢你的答案。有没有可能像定期查询那样对名称和名字应用不同的权重? – 2015-01-30 15:29:55

+1

嗨@哈里。 详细解释这个问题将超出这个问题的范围,并会使这个问题变得非常混乱。你可以看看[这里](http://www.elasticsearch.org/guide/en/elasticsearch/guide/current/_boosting_query_clauses.html),或者提出一个新问题并要求我回答。 Regards, Heschoon – Heschoon 2015-01-31 11:02:34

+0

非常感谢,@Heschoon!这篇文章很有帮助,但我仍然不确定如何使它成为完成建议者的具体工作。任何机会,你可以回答我的[问题](http://stackoverflow.com/q/28268418/2926423)? – 2015-02-01 21:59:56

相关问题