我是 ElasticSearch 的新手,并尝试在数据上使用它,人们可以在其中搜索某些文本(比如 entity.name)并在结果列表上应用排序。

以下是我的映射:

   {
      "entity": {
        "dynamic_templates": [
          { "text_custom_field_template": {
            "match":              "ltd_text_*",
            "mapping": {
              "type":           "text"
            }
          }}
        ],
        "properties": {
          "id": {
            "type": "long",
            "index": "not_analyzed"
          },
          "treeId": {
            "type": "long",
            "index": "not_analyzed"
          }
          "entity.name": {
            "type": "text",
            "fielddata": true,
            "fields": {
              "sort": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          }
          "entity.url": {
            "type": "text"
          },
          "entity.details": {
            "type": "text"
          }
        }
      }
    } 


    id       name            details     is_marked
    13    ABC entity        details        1
    14    BCD  entity        details        1
    15    DEF  entity        details        1
    16    EFG  entity        details        1
    17    GHI                details        1
    18    Untitled entity    details        1

我想搜索名称具有实体的所有实体,然后按字母顺序对结果进行排序。如果我在下面的弹性搜索中运行,我会得到相同的 asc 和 desc 结果:

    {
       "query":{
          "multi_match":{
             "query":"entity",
             "fields":[
                "entity.details^1.0",
                "entity.name^4.0",
             ],
             "type":"best_fields",
             "operator":"AND",
             "slop":0,
             "prefix_length":0,
             "max_expansions":50,
             "lenient":false,
             "zero_terms_query":"NONE",
             "boost":1.0
          }
      },
        "sort":{
        "entity.name.sort" : "asc"
       }
    }

    Result :
    BCD
    EFG
    GHI
    Untitled
    ABC

还有一种方法可以支持客户端可以添加的文本类型的新自定义字段(搜索和排序)吗?