目前,在搜索孩子时,没有任何功能可以返回孩子和父母关系的双方......所以这个想法很简单,实质上是:
1.使用 has_child 来搜索子文档以返回父级 2.使用常规搜索方法仅搜索子文档 我实现了这个目标:
curl -XGET 'IP ADDRESS/elasticsearch/_msearch?pretty=true' -d '{}
{
"query": {
"query_string": {
"query": "text",
"default_field": "text",
"default_operator": "and",
"analyzer": "std"
}
},
"highlight": {
"order": "score",
"tags_schema": "styled",
"encoder": "html",
"fields": {
"text": {
"store": true,
"term_vector": "with_positions_offsets",
"index_analyzer": "std",
"number_of_fragments": 0
}
}
},
"explain": true,
"size": 1000
}
{}
{
"query": {
"has_child": {
"type": "page",
"query": {
"filtered": {
"query": {
"match_all": {}
},
"filter": {
"term": {
"text": "text"
}
}
}
}
}
},
"size": 1000
}
{}'
......所以,目标如下,我正在努力:
答案 0 :(得分:0)
最后我最终做到了这一点...... 两个阶段。
第一阶段 - 查询搜索字词的子文档,同时返回所有父文档 ID
curl -XGET localhost:9200/_msearch?pretty=true' -d' {
"query": {
"top_children": {
"type": "page",
"query":{
"query_string":{
"query":"search string",
"default_field":"text",
"default_operator":"and"
}
},
"score": "max",
"factor": 5,
"incremental_factor": 2
}
},
"fields":["_id"],
"explain":true
}'
第二阶段 - 基于ID返回的多重查询
多搜索查询不能包含空格,有关详细信息,请参阅文档!
curl -XGET 'localhost:9200/_msearch?pretty=true' -d '
{Note: These braces are to specify an index or route information}
{"query":{"filtered":{"query":{"query_string":{"query":"search string","default_field":"text","default_operator":"and"}},"filter":{"term":{"_parent":"public#627405"}}}},"highlight":{"order":"score","tags_schema":"styled","encoder":"html","fields":{"text":{"store": true,"term_vector": "with_positions_offsets","index_analyzer": "std","number_of_fragments": 0}}}}
{}
{another query}
{}
{another etc}'