在PHP的Elasticsearch中优先考虑前缀匹配

shi*_*k01 5 php elasticsearch

在Elasticsearch中,有没有一种方法为前缀匹配赋予比包含该单词的字符串更高的优先级?

例如-如果要搜索的单词优先级ram应如下所示:

Ram Reddy
Joy Ram Das
Kiran Ram Goel
Swati Ram Goel
Ramesh Singh
Run Code Online (Sandbox Code Playgroud)

我已经尝试过按这里给出的映射。我这样做是这样的:

$params = [
        "index" => $myIndex,
            "body" => [
            "settings"=> [
            "analysis"=> [
                "analyzer"=> [
                "start_with_analyzer"=> [
                    "tokenizer"=> "my_edge_ngram",
                    "filter"=> [
                    "lowercase"
                    ]
                ]
                ],
                "tokenizer"=> [
                "my_edge_ngram"=> [
                    "type"=> "edge_ngram",
                    "min_gram"=> 3,
                    "max_gram"=> 15
                ]
                ]
            ]
            ],
            "mappings"=> [
            "doc"=> [
                "properties"=> [
                "label"=> [
                    "type"=> "text",
                    "fields"=> [
                    "keyword"=> [
                        "type"=> "keyword"
                    ],
                    "ngramed"=> [
                        "type"=> "text",
                        "analyzer"=> "start_with_analyzer"
                    ]
                    ]
                ]
                ]
            ]
            ]
    ]
    ];
    $response = $client->indices()->create($params);    // create an index
Run Code Online (Sandbox Code Playgroud)

并像这样搜索:

$body = [
        "size" => 100,

        '_source' => $select,
        "query"=> [
            "bool"=> [
              "should"=> [
                [
                  "query_string"=> [
                    "query"=> "ram*",
                    "fields"=> [
                      "value"
                    ],
                    "boost"=> 5
                  ]
                ],
                [
                  "query_string"=> [
                    "query"=> "ram*",
                    "fields"=> [
                      "value.ngramed"
                    ],
                    "analyzer"=> "start_with_analyzer",
                    "boost"=> 2
                  ]
                ]
              ],
              "minimum_should_match"=> 1
            ]
          ]
    ];

$params = [
    'index' => $myIndex,
    'type' => $myType,
    'body' => []
];
$params['body'] = $body;
$response = $client->search($params);
Run Code Online (Sandbox Code Playgroud)

查询的json如下:

    {
  "size": 100,
  "_source": [
    "label",
    "value",
    "type",
    "sr"
  ],
  "query": {
    "bool": {
      "should": [
        {
          "query_string": {
            "query": "ram*",
            "fields": [
              "value"
            ],
            "boost": 5
          }
        },
        {
          "query_string": {
            "query": "ram*",
            "fields": [
              "value.ngramed"
            ],
            "analyzer": "start_with_analyzer",
            "boost": 2
          }
        }
      ],
      "minimum_should_match": 1,
      "must_not": {
        "match_phrase": {
          "type": "propertyValue"
        }
      }
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

我正在使用elasticsearch 5.3.2是否有其他方法可以使用php中的search方法对关系数据库中的搜索结果进行排序?