如何通过在一个字段中混合两个值来获取弹性搜索中的结果


how to fetch result in elasticsearch by mixing two values in a field?

我想根据一个有两个值的字段获得结果的随机顺序。我的结果是烹饪出了一道价值观是"印度"&"国际"。我想通过很好地混合这个字段的值来显示结果。

{
"query": {
    "function_score": {
      "query": {
        "bool": {
        "must": [
            {
                "terms": {
                    "meta_groups": [
                        "vegan"
                    ],
                    "minimum_should_match": 1
                }
            }
        ]
    }
      },
      "functions": [
        {
          "random_score": {
            "seed": 314159265387
          }
        }
      ],
      "score_mode": "multiply"
    }
  }
}

这是我的结果集

        {
        "_index": "project",
        "_type": "recipes",
        "_id": "9251",
        "_score": 0.53214025,
        "_source": {
           "title": "Grilled Fish With Corn And Pineapple Salsa Recipe",
           "description": "Marinated fish darnes grilled and served with a delicious salsa of corn, tomatoes and pineapple.",
           "source_name": "Sanjeev Kapoor",
           "cuisine": "indian"
        }
     },
     {
        "_index": "project",
        "_type": "recipes",
        "_id": "9235",
        "_score": 0.507389,
        "_source": {
           "title": "Kerela Meen Curry Recipe",
           "description": "Surmai curry - popular Kerela dish",
           "source_name": "Sanjeev Kapoor",
           "cuisine": "indian"
        }
     },
     {
        "_index": "foodini",
        "_type": "recipes",
        "_id": "58",
        "_score": 0.4899247,
        "_source": {
           "title": "Magical Blueberry Vanilla Chia Seed Jam",
           "description": "no-description",
           "source_name": "Oh She Glows",
           "cuisine": "international"
        }
     },
     {
        "_index": "foodini",
        "_type": "recipes",
        "_id": "147",
        "_score": 0.48571476,
        "_source": {
           "title": "Heather's Toasted Super Seed Power Bread",
           "description": "no-description",
           "source_name": "Oh She Glows",
           "cuisine": "international"
        }
     },
     {
        "_index": "foodini",
        "_type": "recipes",
        "_id": "118",
        "_score": 0.4791146,
        "_source": {
           "title": "Easy Tomato Basil Cream Pasta",
           "description": "no-description",
           "source_name": "Swathis kitchen",
           "cuisine": "international"
        }
     }

需要执行某种查询以获得与indian&国际美食。现在是一系列的印度和国际美食。任何线索都将不胜感激。谢谢

找到了这个问题的解决方案。我们可以使用随机方法,避免使用种子。当我们不想把分页带入画面时,种子可能会有所帮助。这是我的代码

{
"from": 15, 
"size": 5, 
"query": {
    "function_score": {
      "query": {
        "bool": {
        "must": [
            {
                "terms": {
                    "meta_groups": [
                        "vegan"
                    ],
                    "minimum_should_match": 1
                }
            }
        ]
    }
      },
      "functions": [
        {
          "random_score": {
            "seed": 31415926255
          }
        }
      ]
    }
  }
 }

这个查询给了我多个有利的

1. Random set of result each time I change the seed. 
2. Helps me in having a random order.
3. Easily maintainable pagination.