Found the answer. I needed to use "more_like_this_field" instead of "more_like_this"
ElasticSearch more_like_this not restricting to title filed
-
01-07-2022 - |
Domanda
The following code restricts all results to the "thread", "_id" which is great.
$data_string = '{
"from" : 0, "size" : 100,
"sort" : [
{ "date" : {"order" : "desc"} }
],
"query": {
"match" : {
"thread.title" : {
"query" : "This is a test"
}
}
}
}';
What I would like to do is use the more_like_this function instead of match. The following code works, but returns results from "post", "_id" as well as "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
}
}
}
}';
What do I need to do to restrict results to just "thread", "_id".
This is my mappings:
{
"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"
}
}
}
}
Nessuna soluzione corretta
Altri suggerimenti
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow