在Elasticsearch,与function_score助推给出的以下文件结构:弹性搜索嵌套性
"workhistory": {
"positions": [{
"company": "Some company",
"position": "Some Job Title",
"start": 1356998400,
"end": 34546576576,
"description": "",
"source": [
"some source",
"some other source"
]
},
{
"company": "Some other company",
"position": "Job Title",
"start": 1356998400,
"end": "",
"description": "",
"source": [
"some other source"
]
}]
}
和映射这样的结构:
我希望能够在“企业搜索“并匹配公司的文件=”某公司“等等。然后我想获得tf idf _score。我还想创建一个function_score查询来根据“source”字段数组的值提高此匹配的分数。基本上,如果源包含“某些源”,则用x数量提升_分数。如果需要,我可以更改“源”属性的结构。
这是我走到这一步:
{
"bool": {
"should": [
{
"filtered": {
"query": {
"bool": {
"should": [
{
"bool": {
"should": [
{
"match": {
"workhistory.positions.company.original": "some company"
}
}
]
}
}
],
"minimum_should_match": "100%"
}
},
"filter": {
"and": [
{
"bool": {
"should": [
{
"term": {
"workhistory.positions.company.original": "some company"
}
}
]
}
}
]
}
}
},
{
"function_score": {
"query": {
"bool": {
"should": [
{
"bool": {
"should": [
{
"match": {
"workhistory.positions.company.original": "some company"
}
}
]
}
}
],
"minimum_should_match": "100%"
}
},
"filter": {
"and": [
{
"bool": {
"should": [
{
"term": {
"workhistory.positions.company.original": "some company"
}
}
]
}
}
]
}
}
}
]
}
}
有在这里一些过滤器为好,因为我只想与滤波值返回文档。在这个例子中,过滤器和查询基本上是相同的,但在这个查询的更大版本中,我有一些其他的“可选”匹配来提高可选值等等。现在function_score并没有太多的工作,因为我无法真正地了解如何使用它。目标是能够调整我的应用程序代码中的提升数量并将其传递给搜索查询。
我正在使用Elasticsearch版本1.3.4。
这似乎是工作,我切换出的脚本是在脚本的脚本文件夹来无法启用动态脚本。我快到了,但是我需要先对普通查询进行评分,然后应用此查询来提高我的function_score查询的分数。因此,结果将首先对文档中的匹配进行排序,然后通过此功能进行提升。 – 2014-10-08 05:10:02
我也不知道如何应用不同的提升,如果源被命名为别的东西,或根本不存在。这会匹配相同的嵌套元素,还是该数组中的任何元素? – 2014-10-08 05:13:44
对另一个“源”值的不同提升很简单:您只需定义另一组“{”filter“:{},”script_score“:{}}'。我更新了我的答案。 – 2014-10-08 05:27:52