使用elasticsearch java api创建带有同义词和映射的索引

时间:2017-07-18 08:33:32

标签: java elasticsearch

我尝试通过java api在elasticsearch中实现同音异义词。我没有任何例外,但它只是不起作用。

当我想使用BoolQueryBuilder进行搜索时,如果我输入存在的内容的同义词,它将找不到任何内容。

Settings settings = Settings.builder().loadFromSource(jsonBuilder()
    .startObject()
      .startObject("analysis")
        .startObject("analyzer")
          .startObject("synonym")
            .field("tokenizer", "whitespace")
            .field("filter", new String[] {"synonym"})
          .endObject()
        .endObject()
        .startObject("filter")
          .startObject("synonym")
            .field("type", "synonym")
            .field("synonyms", new String[] {"Highlandstreet, ravioli"})
            .field("ignore_case", true)
            .field("expand", true)
          .endObject()
        .endObject()
      .endObject()
    .endObject().string(), XContentType.JSON).build();

  XContentBuilder content = jsonBuilder()
    .startObject()
      .startObject("properties")
        .startObject("title")
          .field("type", "string")
          .field("analyzer", "synonym")
        .endObject()
        .startObject("location")
          .field("type", "geo_point")
        .endObject()
      .endObject()
    .endObject();

  CreateIndexResponse response =
    node.client().admin().indices().prepareCreate("index_name").setSettings(settings)
      .addMapping("mapping_name1", content)
      .addMapping("mapping_name2", content)
      .addMapping("mapping_name3", content)
      .addMapping("mapping_name4", content)
      .addMapping("mapping_name5", content)
      .addMapping("mapping_name6", content)
      .addMapping("mapping_name7", content).get();

0 个答案:

没有答案