使用 Elastica 的 Elasticsearch MLT 查询 PHP
Elasticsearch MLT query with Elastica for PHP
想知道这是否来自 Elasticsearch official doc:
{
"more_like_this" : {
"fields" : ["name.first", "tweet"],
"like" : [
{
"_index" : "marvel",
"_type" : "quotes",
"doc" : {
"name": {
"first": "Ben",
"last": "Grimm"
},
"tweet": "You got no idea what I'd... what I'd give to be invisible."
}
},
],
"min_term_freq" : 1,
"max_query_terms" : 1
}
}
是否已在最新版本的 Elastica 中实现?
我正在努力解决的问题是 "like".
的 "doc" 部分
我的代码如下:
$moreLikeThis = (new Query\MoreLikeThis())
->setFields([
'name.first',
'tweet'
])
->setLike((new Document())
->setIndex('myIndexName')
->setType('myTypeName')
->setData([
'tweet' => 'Foo',
'name' => [
'first' => 'Bar',
'last' => 'Test'
]
])
)
->setMinTermFrequency(1)
->setMinDocFrequency(1);
但看起来查询生成不正确。这是我 var_dump() Request::toString():
时得到的结果
string(398)
"{"path":"myIndexName/myTypeName/_search","method":"GET","data":{"query":{"more_like_this":{"fields":["name.first","tweet"],"like":{"_id":"","_type":"myTypeName","_index":"myIndexName"},"min_term_freq":1,"min_doc_freq":1}}},"query":{"search_type":"count"},"connection":{"config":[],"host":"localhost","port":9200,"enabled":true}}"
"doc" 部分是否确实缺失?是我用的不对吗?
如果有人想知道,该功能实际上并未在 Elastica 中完全实现。
想知道这是否来自 Elasticsearch official doc:
{
"more_like_this" : {
"fields" : ["name.first", "tweet"],
"like" : [
{
"_index" : "marvel",
"_type" : "quotes",
"doc" : {
"name": {
"first": "Ben",
"last": "Grimm"
},
"tweet": "You got no idea what I'd... what I'd give to be invisible."
}
},
],
"min_term_freq" : 1,
"max_query_terms" : 1
}
}
是否已在最新版本的 Elastica 中实现? 我正在努力解决的问题是 "like".
的 "doc" 部分我的代码如下:
$moreLikeThis = (new Query\MoreLikeThis())
->setFields([
'name.first',
'tweet'
])
->setLike((new Document())
->setIndex('myIndexName')
->setType('myTypeName')
->setData([
'tweet' => 'Foo',
'name' => [
'first' => 'Bar',
'last' => 'Test'
]
])
)
->setMinTermFrequency(1)
->setMinDocFrequency(1);
但看起来查询生成不正确。这是我 var_dump() Request::toString():
时得到的结果string(398) "{"path":"myIndexName/myTypeName/_search","method":"GET","data":{"query":{"more_like_this":{"fields":["name.first","tweet"],"like":{"_id":"","_type":"myTypeName","_index":"myIndexName"},"min_term_freq":1,"min_doc_freq":1}}},"query":{"search_type":"count"},"connection":{"config":[],"host":"localhost","port":9200,"enabled":true}}"
"doc" 部分是否确实缺失?是我用的不对吗?
如果有人想知道,该功能实际上并未在 Elastica 中完全实现。