【问题标题】:Elasticsearch with Tire, highlight not working使用轮胎的 Elasticsearch,突出显示不起作用
【发布时间】:2012-08-08 02:28:58
【问题描述】:

我必须在这里遗漏一些东西,但是当我尝试使用 Elasticsearch 进行搜索时突出显示,我根本没有看到任何突出显示,但也没有错误。我不认为这是轮胎问题,但我提到轮胎以防万一它很重要。使用 Tire 的索引非常简单(为简洁起见,删除了一些字段):

mapping :_source => { :excludes => ['attachment'] } do
  indexes :id, :type => 'integer'
  indexes :title, :store => true
  indexes :attachment, :type => 'attachment', :_source => { :enabled => false }
end

使用 curl,我可以尝试这个查询,它工作正常,但结果中没有突出显示:

curl -XPOST http://localhost:9200/myobject/_search\?pretty\=true -d '{             
  "query": {"query_string": {"query": "foobar"}},
  "highlight": {"fields": {"Title":{}}}
}'

请注意,我在映射中添加了“:store => true”只是为了确保,尽管我认为没有必要进行突出显示。所以我猜我在映射或查询规范中遗漏了一些东西,但我没有看到它。任何建议将不胜感激。谢谢。

【问题讨论】:

    标签: highlighting elasticsearch tire


    【解决方案1】:

    elasticsearch 中的字段名称区分大小写。 Titletitle 是两个不同的字段。试试这个查询:

    curl -XPOST http://localhost:9200/myobject/_search\?pretty\=true -d '{             
      "query": {"query_string": {"query": "foobar"}},
      "highlight": {"fields": {"title":{}}}
    }
    

    【讨论】:

    • 太棒了,谢谢。被索引的原始数据对象中的字段称为“Title”,但看起来轮胎映射是“:title”将其映射为小写,我应该在 curl 的输出中注意到但不知何故错过了。 curl 现在可以工作,但使用 Tire 并不总是能正确突出显示。单行 "s = MyObject.search(q, :highlight => :title)" 不起作用,但带有 "highlight :title" 的块搜索可以。无论如何,非常感谢您的快速帮助。
    猜你喜欢
    • 1970-01-01
    • 2023-03-10
    • 2014-09-20
    • 2014-10-24
    • 2013-09-26
    • 2013-07-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多