2013-01-17 53 views
1

我無法使elasticsearch結果突出顯示工作。我找到了很多例子並嘗試了不同的版本,但是我沒有將它應用到我自己的索引中。我究竟做錯了什麼?elasticsearch突出顯示結果中缺失的屬性

這裏是我的測試腳本:

init() { 
    curl -XDELETE http://localhost:9200/twitter 
    echo 
    curl -XPUT http://localhost:9200/twitter 
    echo 

    curl -XPUT http://localhost:9200/twitter/tweet/_mapping -d '{ 
     "tweet" : { 
      "properties" : { 
       "user" : { "type" : "string" }, 
       "message" : { 
        "type" : "string", 
        "index": "analyzed", 
        "store": "yes", 
        "term_vector" : "with_positions_offsets" 
       } 
      } 
     } 
    }' 
    echo 
    curl -XPOST http://localhost:9200/twitter/tweet -d '{ 
     "user": "kimchy", 
     "message": "You know, for Search" 
    }' 
    echo 
    curl -XPOST http://localhost:9200/twitter/tweet -d '{ 
     "user": "bar", 
     "message": "You know, foo for Search" 
    }' 
    echo 

    sleep 2 
    echo '-------------------' 
} 

[ "$1" = "init" ] && init 

curl -X GET 'http://localhost:9200/twitter/_search/?pretty=true' -d '{ 
    "query":{ 
      "query_string":{ 
       "query":"foo" 
      } 
     } 
    }, 
    "highlight":{ 
     "pre_tags": "<b>", 
     "post_tags": "</b>", 
     "fields" : { 
      "message" : {"number_of_fragments": 20} 
     } 
    } 
}' 

這裏輸出:

{ 
    "took" : 4, 
    "timed_out" : false, 
    "_shards" : { 
    "total" : 5, 
    "successful" : 5, 
    "failed" : 0 
    }, 
    "hits" : { 
    "total" : 1, 
    "max_score" : 0.09492774, 
    "hits" : [ { 
     "_index" : "twitter", 
     "_type" : "tweet", 
     "_id" : "1tgGWGhnRLy-nJIAunFeeQ", 
     "_score" : 0.09492774, "_source" : { 
     "user": "bar", 
     "message": "You know, foo for Search" 
    } 
    } ] 
    } 
}% 

正如你所看到的亮點屬性完全丟失。

回答

3

您的查詢部分太多關閉大括號:

"query":{ 
     "query_string":{ 
      "query":"foo" 
     } 
    } <---- This one is not needed. 
}, 

所以高亮部分簡單地由解析器忽略。

順便說一句,在pre_tagspost_tags應該是數組:

curl "localhost:9200/twitter/tweet/_search?pretty=true" -d '{ 
    "query": { 
     "query_string": { 
      "query": "foo" 
     } 
    }, 
    "highlight": { 
     "pre_tags": ["<b>"], 
     "post_tags": ["</b>"], 
     "fields": { 
      "message": {"number_of_fragments": 20} 
     } 
    }  
}' 
+0

我不知道這是可能有額外的右括號,而不會造成任何分析器錯誤:) – bara