Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/database/9.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
Database 先有符合条件的结果_Database_<img Src="//i.stack.imgur.com/RUiNP.png" Height="16" Width="18" Alt="" Class="sponsor Tag Img">elasticsearch - Fatal编程技术网 elasticsearch,Database,elasticsearch" /> elasticsearch,Database,elasticsearch" />

Database 先有符合条件的结果

Database 先有符合条件的结果,database,elasticsearch,Database,elasticsearch,给出一个非常简单的文档: `concert_name` - String containing the name of the concert `city` - City ID of the concert `band` - Band ID `relevance` - An integer that indicate how important the concert is 我想在一个特定的城市举办所有的音乐会,但我想先举办一个特定乐队的音乐会(按相关性排序),然后再举办其他所有的音乐会(按

给出一个非常简单的文档:

`concert_name` - String containing the name of the concert 
`city` - City ID of the concert
`band` - Band ID
`relevance` - An integer that indicate how important the concert is
我想在一个特定的城市举办所有的音乐会,但我想先举办一个特定乐队的音乐会(按相关性排序),然后再举办其他所有的音乐会(按相关性排序)

因此,我可以进行如下查询:

给我所有在
米兰举行的音乐会
,并首先返回
珍珠酱的音乐会


如何在Elastica 1.X中执行此操作?

编辑1

我认为这可以通过在多个字段上使用来完成。你必须这么做。我给你想要匹配的波段赋值10,其他波段的值为0。试试这样的

{
  "query": {
    "match": {
      "city": "milan"
    }
  },
  "sort": [
    {
      "_script": {
        "script": "if(doc['band'].value == 'pearl') {10} else {0}",
        "type": "number",
        "order": "desc"
      }
    },
    {
      "relevance": {
        "order": "desc"
      }
    }
  ]
}
我假设数字越大,音乐会就越重要。我已经在
ES 1.7上对此进行了测试


这有帮助吗?

编辑1

我认为这可以通过在多个字段上使用来完成。你必须这么做。我给你想要匹配的波段赋值10,其他波段的值为0。试试这样的

{
  "query": {
    "match": {
      "city": "milan"
    }
  },
  "sort": [
    {
      "_script": {
        "script": "if(doc['band'].value == 'pearl') {10} else {0}",
        "type": "number",
        "order": "desc"
      }
    },
    {
      "relevance": {
        "order": "desc"
      }
    }
  ]
}
我假设数字越大,音乐会就越重要。我已经在
ES 1.7上对此进行了测试


这有帮助吗?

是的,但这不会首先返回特定乐队的歌曲。相关性与乐队无关?我的意思是每个乐队都有自己的关联性,对吧?不,关联性与音乐会有关。因此,首先返回我在查询中指定的乐队的音乐会(并按相关性排序),然后返回该城市的所有其他音乐会(也按相关性排序)。在理解您的评论后,我更新了我的答案,这是您想要的吗?查看查询,似乎是正确的答案。在接受答案之前要检查它。是的,但这不会首先返回特定乐队的。相关性与乐队无关?我的意思是每个乐队都有自己的关联性,对吧?不,关联性与音乐会有关。因此,首先返回我在查询中指定的乐队的音乐会(并按相关性排序),然后返回该城市的所有其他音乐会(也按相关性排序)。在理解您的评论后,我更新了我的答案,这是您想要的吗?查看查询,似乎是正确的答案。我会在接受答案之前检查一下。