elasticsearch 使用Elastic Search搜索特殊字符,如#和+

bqf10yzr  于 2023-04-11  发布在  ElasticSearch
关注(0)|答案(1)|浏览(293)

我在我的项目中使用标准分析器,但当我想根据标题搜索工作时,使用一些特殊字符,如#或+,它不起作用,返回的项目包含所需的文本。

@Data
@Document(indexName = "jobs")
public final class Job {

    @Id
    private Long id;

    @Field(type = FieldType.Long)
    private Long userId;

    @Field(type = FieldType.Text, analyzer = "standard")
    private String title;

    @Field(type = FieldType.Text, analyzer = "standard")
    private String description;

    @Field(type = FieldType.Keyword)
    private JobStatus status;
}
z3yyvxxp

z3yyvxxp1#

standard analyzer使用,standard tokenizer。标准标记器使用Unicode Standard Annex #29标记您的“文本”并删除您案例中的+#

你能做什么?

1.您可以使用.keyword字段。默认情况下不会对其进行分析。
1.您可以使用custom analyzer创建新字段。
详细信息:

GET _analyze
{
  "text": ["test+test#test  ### +++"]
}
{
  "tokens": [
    {
      "token": "test",
      "start_offset": 0,
      "end_offset": 4,
      "type": "<ALPHANUM>",
      "position": 0
    },
    {
      "token": "test",
      "start_offset": 5,
      "end_offset": 9,
      "type": "<ALPHANUM>",
      "position": 1
    },
    {
      "token": "test",
      "start_offset": 10,
      "end_offset": 14,
      "type": "<ALPHANUM>",
      "position": 2
    }
  ]
}

相关问题