2013-05-07 79 views
1

我的目標是應用推動了場「名」(見下面的例子),但我有兩個問題,當我搜索「約翰」:如何在elasticsearch中增強某些字段而不是其他字段?

  1. 搜索也匹配{name: "dany", message: "hi bob"}時名稱爲「丹尼」和
  2. 搜索不提高名義在消息(與行名稱=「約翰」應該是頂部)

要點是https://gist.github.com/tomaspet262/5535774

(因爲計算器的FO rm submit returned'您的文章似乎包含未正確格式化爲代碼的代碼',格式正確)。

+0

編輯爲包含蜱(即''')以正確格式化代碼 – 2013-05-08 18:25:03

回答

0

我會建議使用查詢時間提升而不是索引時間提升。

#DELETE 
curl -XDELETE 'http://localhost:9200/test' 
echo 
# CREATE 
curl -XPUT 'http://localhost:9200/test?pretty=1' -d '{ 
    "settings": { 
     "analysis" : { 
      "analyzer" : { 
       "my_analyz_1" : { 
        "filter" : [ 
         "standard", 
         "lowercase", 
         "asciifolding" 
        ], 
        "type" : "custom", 
        "tokenizer" : "standard" 
       } 
      } 
     } 
    } 
}' 
echo 
# DEFINE 
curl -XPUT 'http://localhost:9200/test/posts/_mapping?pretty=1' -d '{ 
    "posts" : { 
     "properties" : { 
      "name" : { 
       "type" : "string", 
       "analyzer" : "my_analyz_1" 
      }, 
      "message" : { 
       "type" : "string", 
       "analyzer" : "my_analyz_1" 
      } 
     } 
    } 
}' 
echo 
# INSERT 
curl localhost:9200/test/posts/1 -d '{name: "john", message: "hi john"}' 
curl localhost:9200/test/posts/2 -d '{name: "bob", message: "hi john, how are you?"}' 
curl localhost:9200/test/posts/3 -d '{name: "john", message: "bob?"}' 
curl localhost:9200/test/posts/4 -d '{name: "dany", message: "hi bob"}' 
curl localhost:9200/test/posts/5 -d '{name: "dany", message: "hi john"}' 
echo 
# REFRESH 
curl -XPOST localhost:9200/test/_refresh 
echo 
# SEARCH 
curl "localhost:9200/test/posts/_search?pretty=1" -d '{ 
    "query": { 
     "multi_match": { 
      "query": "john", 
      "fields": ["name^2", "message"] 
     } 
    } 
}' 
+0

非常感謝!它像魔術般運作:)。 – Tomas 2013-05-08 15:46:02

0

林不知道如果這是在這種情況下,相關性,但這樣的少量數據測試的時候,我總是用1個碎片,而不是默認設置,以確保沒有因爲分佈式計算的問題。

相關問題