查找弹性搜索中我们有一行字符的次数 [英] Find number of times we have a character in a row in elastic search

查看:122
本文介绍了查找弹性搜索中我们有一行字符的次数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在进行弹性搜索,并且面临一个问题,即搜索记录中连续出现多少个单词。 / p>

  {
{user:Aniket,postDate:2016-04-26身体:我们昨天讨论一次搜索,标题:一次性单词}
},
{
user:aniket,postDate :2016-04-26,身体:分布很难,分布应该很简单,单词字词,标题:四次字}
},
{ 用户:aniket,postDate:2016-04-26,body:分布很难,分发应该是easy.word word word,title:Three times word}
},
{user:aniket,
postDate:2016-04-26,
body:发行很难,分配应该是简单字词,
title:两次字
}

我在用户aniket以下有四行,我们在每一行都有单词,但有时它会出现二,三,四或一次。
我需要结果,如果我搜索单词,我们在结果中发现单词四次,比顶部如下:
1.单词单词单词
2。词语单词
3.单词
4.单词
我尝试了分数,但分数不会为我提供与之相关的任何信息。

解决方案

您需要脚本排序。这样的东西:

 sort:{
_script:{
type number,
script:termInfo = _index ['body'] [term] .tf(); return termInfo;,
params:{
term :word
},
lang:groovy,
order:desc
}
}

并在 elasticsearch.yml 文件中启用Groovy脚本:

  script.groovy.sandbox.enabled:true 

而且,您还需要使用适当的分析器。对于你的情况,例如,使用标准分析器(默认情况下),您将不会在 easy.word 。为了使排序工作,您需要一个分析器,例如


I am working on elasticsearch and facing an issue that how many time a word comes in a row at the time search records.

Like I have following rows:

{
 { "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"
}

I have above four rows under user aniket and we have "word" in each row but sometimes it goes two,three,four or one time. I need the result like if I search for "word" and we found word four times in the result than it will come at the top like: 1. word word word word 2. word word word 3. word word 4. word I tried with score too but score is not going to provide me any information related to that.

解决方案

You need script sorting. Something like this:

  "sort": {
    "_script": {
      "type": "number",
      "script": "termInfo=_index['body'][term].tf();return termInfo;",
      "params": {
        "term": "word"
      },
      "lang": "groovy",
      "order": "desc"
    }
  }

And enable Groovy scripting in elasticsearch.yml file:

script.groovy.sandbox.enabled: true

And, also, you need to use a proper analyzer. For you case, for example, using the standard analyzer (the default one) you won't get a split at easy.word. For that sorting to work, you'd need an analyzer that will split at . for example.

这篇关于查找弹性搜索中我们有一行字符的次数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆