ElasticSearch more_like_this不限制提交标题

时间:2013-10-23 14:46:26

标签: elasticsearch morelikethis

以下代码将所有结果限制在"线程"," _id"这很棒。

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

我想要做的是使用more_like_this函数而不是匹配。以下代码有效,但返回" post"," _id"的结果。以及"线程"," _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
            }
        }
    }
}';

我需要做些什么才能将结果限制为"线程"," _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"
        }
      }
    }
  }

1 个答案:

答案 0 :(得分:0)

找到答案。我需要使用“more_like_this_field”而不是“more_like_this”