2013-10-23 58 views
0

以下代碼將所有結果限制爲「線程」,「_id」,這非常棒。ElasticSearch more_like_this不限於標題字段

$data_string = '{ 
"from" : 0, "size" : 100, 
"sort" : [ 
    { "date" : {"order" : "desc"} } 
], 
"query": { 
     "match" : { 
      "thread.title" : { 
       "query" : "This is a test" 
      } 
     } 
    } 
}'; 

我想要做的是使用more_like_this函數而不是匹配。以下代碼有效,但返回「post」,「_id」以及「thread」,「_id」的結果。

$data_string = '{ 
"from" : 0, "size" : 100, 
"sort" : [ 
    { "date" : {"order" : "desc"} } 
], 
"query": { 
     "more_like_this" : { 
      "thread.title" : { 
       "like_text" : "This is a test", 
       "min_word_len" : 2, 
       "min_term_freq" : 1, 
       "min_doc_freq" : 1 
      } 
     } 
    } 
}'; 

我需要做些什麼才能將結果限制爲「thread」,「_id」。

這是我的映射:

{ 
    "xenforo120" : { 
    "post" : { 
     "_source" : { 
     "enabled" : false 
     }, 
     "properties" : { 
     "date" : { 
      "type" : "long", 
      "store" : "yes" 
     }, 
     "discussion_id" : { 
      "type" : "long", 
      "store" : "yes" 
     }, 
     "message" : { 
      "type" : "string", 
      "analyzer" : "tweet_analyzer" 
     }, 
     "node" : { 
      "type" : "long" 
     }, 
     "thread" : { 
      "type" : "long" 
     }, 
     "title" : { 
      "type" : "string" 
     }, 
     "user" : { 
      "type" : "long", 
      "store" : "yes" 
     } 
     } 
    }, 
    "profile_post" : { 
     "_source" : { 
     "enabled" : false 
     }, 
     "properties" : { 
     "discussion_id" : { 
      "type" : "long", 
      "store" : "yes" 
     }, 
     "message" : { 
      "type" : "string", 
      "analyzer" : "tweet_analyzer" 
     }, 
     "title" : { 
      "type" : "string" 
     }, 
     "user" : { 
      "type" : "long", 
      "store" : "yes" 
     } 
     } 
    }, 
    "page" : { 
     "properties" : { 
     "date" : { 
      "type" : "long" 
     }, 
     "discussion_id" : { 
      "type" : "long" 
     }, 
     "message" : { 
      "type" : "string" 
     }, 
     "node" : { 
      "type" : "long" 
     }, 
     "title" : { 
      "type" : "string" 
     }, 
     "user" : { 
      "type" : "long" 
     } 
     } 
    }, 
    "thread" : { 
     "_source" : { 
     "enabled" : false 
     }, 
     "properties" : { 
     "date" : { 
      "type" : "long", 
      "store" : "yes" 
     }, 
     "discussion_id" : { 
      "type" : "long", 
      "store" : "yes" 
     }, 
     "message" : { 
      "type" : "string", 
      "analyzer" : "tweet_analyzer" 
     }, 
     "node" : { 
      "type" : "long" 
     }, 
     "thread" : { 
      "type" : "long" 
     }, 
     "title" : { 
      "type" : "string" 
     }, 
     "user" : { 
      "type" : "long", 
      "store" : "yes" 
     } 
     } 
    } 
    } 

回答

0

找到了答案。我需要使用「more_like_this_field」而不是「more_like_this」