Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/sorting/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sorting 在弹性搜索中查找一个单词在一行中的次数_Sorting_<img Src="//i.stack.imgur.com/RUiNP.png" Height="16" Width="18" Alt="" Class="sponsor Tag Img">elasticsearch - Fatal编程技术网 elasticsearch,Sorting,elasticsearch" /> elasticsearch,Sorting,elasticsearch" />

Sorting 在弹性搜索中查找一个单词在一行中的次数

Sorting 在弹性搜索中查找一个单词在一行中的次数,sorting,elasticsearch,Sorting,elasticsearch,我正在研究elasticsearch,并面临一个问题,即一个单词在搜索记录中连续出现的次数。 我有以下几行: { { "user":"Aniket", "postDate":"2016-04-26","body":"Search as we discuss yesterday one time word", "title":"One time word"} }, { "user": "aniket", "postDate": "2016-04-26", "body": "Distributio

我正在研究elasticsearch,并面临一个问题,即一个单词在搜索记录中连续出现的次数。 我有以下几行:

{
{ "user":"Aniket", "postDate":"2016-04-26","body":"Search as we discuss yesterday one time word", "title":"One time word"}
}, 
{
"user": "aniket", "postDate": "2016-04-26", "body": "Distribution is hard. Distribution should be easy.word word word word" , "title": "Four times word"}
}, 
{"user": "aniket", "postDate": "2016-04-26", "body": "Distribution is hard. Distribution should be easy.word word word" , "title": "Three times word"}
}, 
{"user": "aniket", 
"postDate": "2016-04-26", 
"body": "Distribution is hard. Distribution should be easy.word word" ,
"title": "Two times word"
}
我在用户aniket下面有四行,每行都有“word”,但有时会有两行、三行、四行或一行。我需要这样的结果,如果我搜索“单词”,我们在结果中找到单词四次,然后它会出现在顶部,如:1。单词2。单词3。单词4。我也试过使用score这个词,但score不会提供任何与此相关的信息

我正在尝试以下查询

curl -XGET 'localhost:9200/blog/post/_search?pretty=1' -d '{
"query": {
"match": {
"body": "word"
}
},
"sort": {
"_script": {
"type": "number",
"script": "termInfo=_index['body'][term].tf();return termInfo;",
"params": {
"term": "word"
},
"lang": "groovy",
"order": "desc"
}
}
}'
得到这个错误:

{
"index" : "blog",
"shard" : 4,
"status" : 500,
"reason" : "QueryPhaseExecutionException[[blog][4]: query[filtered(body:word)->cache(type:post)],from[0],size[10],sort[script\": org.elasticsearch.index.fielddata.fieldcomparator.DoubleScriptDataComparator$InnerSource@51c07776>!]: Query Failed [Failed to execute main query]]; nested: GroovyScriptExecutionException[MissingPropertyException[No such property: body for class: Script5]]; "
} ]

如果我删除了查询中的排序部分,那么即使我使用简单的排序,也会给出结果,然后按asc对body和order进行排序,这样它也可以正常工作,但不是我们的字数情况。有什么解决方案和我缺少的吗?

请按照我的指示,检查“\u解释”的内容:

其中包含了单词的计数:

"value": 3,
"description": "termFreq=3.0",
"details": []

按照以下说明操作:正如我在你的另一篇文章中所问的--请提供
curl-XGET”的输出http://localhost:9200/blog/post/_search“-d'{”query:{“match_all”:{}},“size”:1}'
"value": 3,
"description": "termFreq=3.0",
"details": []