【问题标题】:Elastic Search Python: must inlcuded all words and sorted by word order to resultsElastic Search Python:必须包含所有单词并按单词顺序排序到结果
【发布时间】:2021-11-09 07:59:20
【问题描述】:

必须包含所有单词并按单词顺序排序到 Elastic Search 的结果中

怎么做?

我的意思是我有 python 查询:

result = es.search(index="main_database", body={"query": {"match": {'Full_texts':es_query}}}, size=50)

问题是:'Full_texts' 中至少有一个词,然后它会给我结果。

对我来说,我希望所有单词都必须包含并保持单词顺序。

例如:搜索结果的顶部满足以上所有 就像我的要求一样,中间和底部结果与默认的 Elastic 搜索结果相同。

【问题讨论】:

    标签: python elasticsearch


    【解决方案1】:

    您需要使用intervals queryspan near

    分别带有orderedin_order参数

    【讨论】:

    • 那该怎么做呢?
    【解决方案2】:

    尝试使用 operator and 进行 Elasticsearch 匹配查询。

    搜索查询将是

    {
        "query": {
            "match": {
                "Full_texts": {
                    "query": "<your_query_input_goes_here>",
                    "operator": "and"
                }            
            }
        }
    }
    

    但是,字序不保证,如果您严格要求字序,也请参考the answer of @ExploZe

    【讨论】:

      猜你喜欢
      • 2012-11-28
      • 1970-01-01
      • 2018-07-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多