Reputation: 1015
All my Elasticsearch queries are working fine except when I am using the "more_like_this" feature, I allways get the "Expected field name but got START_OBJECT 'more_like_this'" error.
Here is my "array" with a regular query : (that is working fine)
Array
(
[index] => videos
[from] => 0
[size] => 75
[body] => Array
(
[query] => Array
(
[bool] => Array
(
[must] => Array
(
[0] => Array
(
[match] => Array
(
[gender] => 1
)
)
[1] => Array
(
[match_phrase] => Array
(
[title] => my super title
)
)
[2] => Array
(
[range] => Array
(
[date] => Array
(
[lte] => 1525258744
)
)
)
)
)
)
[sort] => Array
(
[date] => Array
(
[order] => desc
)
)
)
)
And here is one with the more_like_this option : (that dont work)
Array
(
[index] => videos
[from] => 0
[size] => 75
[body] => Array
(
[query] => Array
(
[bool] => Array
(
[must] => Array
(
[0] => Array
(
[match] => Array
(
[gender] => 1
)
)
[1] => Array
(
[range] => Array
(
[date] => Array
(
[lte] => 1525258700
)
)
)
)
)
[more_like_this] => Array
(
[fields] => Array
(
[0] => title
)
[like_text] => my super title
[min_term_freq] => 1
[max_query_terms] => 12
)
)
)
)
Upvotes: 0
Views: 150
Reputation: 1015
Found the answer (thank to @Val), more_like_this should be part of the must array :
Array
(
[index] => videos
[from] => 0
[size] => 75
[body] => Array
(
[query] => Array
(
[bool] => Array
(
[must] => Array
(
[0] => Array
(
[match] => Array
(
[gender] => 1
)
)
[1] => Array
(
[more_like_this] => Array
(
[fields] => Array
(
[0] => title
)
[like_text] => my super title
[min_term_freq] => 1
[max_query_terms] => 12
)
)
[2] => Array
(
[range] => Array
(
[date] => Array
(
[lte] => 1525269403
)
)
)
)
)
)
)
)
Upvotes: 0