无法在 elasticsearch 6.1.2 的映射中插入 "index":"not_analyzed"

拉维蒂娅·甘诺朱

我试图找到一个匹配的名称区分大小写。当我尝试下面的代码时,它按预期工作,不区分大小写。

        HashMap<String, String> data = new HashMap<String, String>();
        data.put("GroupId", "3");
        data.put("GroupName", "testGroup three");
        data.put("CreatedDateTime", "20180115130026757+0000");
        data.put("UpdatedDateTime", "20180115130026757+0000");
        data.put("Createdby", "3");
        data.put("GroupUser",  "{1,2,3,4}");
        data.put("status", "active");

        String mapping = {"typename":{"properties":{
        "GroupName":{"type":"text","index":"not_analyzed"},
        "Createdby":{"type":"text","index":"not_analyzed"},
        "GroupUser":{"type":"text","index":"not_analyzed"},
        "UpdatedDateTime":{"type":"text","index":"not_analyzed"},
        "CreatedDateTime":{"type":"text","index":"not_analyzed"},
        "GroupId":{"type":"text","index":"not_analyzed"},
        "status":{"type":"text","index":"not_analyzed"}}}}

        client = new PreBuiltTransportClient(settings).addTransportAddresses(new TransportAddress(new InetSocketAddress(ipaddress, port)));

        //inserting record
        IndexResponse response = client.prepareIndex(indexName, typeName).setSource(data).get();

        //inserting mapping
        client.admin().indices().preparePutMapping(indexName)
        .setType("typeName")
        .setSource(mapping, XContentType.JSON)
        .get();

为了找到区分大小写的值,我发现使用索引作为 not_analyzed。我尝试了以下

        HashMap<String, String> data = new HashMap<String, String>();
        data.put("GroupId", "3");
        data.put("GroupName", "testGroup three");
        data.put("CreatedDateTime", "20180115130026757+0000");
        data.put("UpdatedDateTime", "20180115130026757+0000");
        data.put("Createdby", "3");
        data.put("GroupUser",  "{1,2,3,4}");
        data.put("status", "active");

        String mapping = {"typename":{"properties":{
        "GroupName":{"type":"text","index":"not_analyzed"},
        "Createdby":{"type":"text","index":"not_analyzed"},
        "GroupUser":{"type":"text","index":"not_analyzed"},
        "UpdatedDateTime":{"type":"text","index":"not_analyzed"},
        "CreatedDateTime":{"type":"text","index":"not_analyzed"},
        "GroupId":{"type":"text","index":"not_analyzed"},
        "status":{"type":"text","index":"not_analyzed"}}}}

        client = new PreBuiltTransportClient(settings).addTransportAddresses(new TransportAddress(new InetSocketAddress(ipaddress, port)));

        //inserting record
        IndexResponse response = client.prepareIndex(indexName, typeName).setSource(data).get();

        //inserting mapping
        client.admin().indices().preparePutMapping(indexName)
        .setType("typeName")
        .setSource(mapping, XContentType.JSON)
        .get();

我收到如下所示的异常

 java.lang.IllegalArgumentException: Could not convert [GroupName.index] to boolean

我想完成以下两个场景:

 1. Find by case sensitive
 2. Find by case insensitive.

弹性搜索版本是 6.1.2。

任何帮助都非常感谢。

更新-1

根据@Val,我已将代码更改为:

    HashMap<String, String> data = new HashMap<String, String>();
    data.put("GroupId", "3");
    data.put("GroupName", "testGroup three");
    data.put("CreatedDateTime", "20180115130026757+0000");
    data.put("UpdatedDateTime", "20180115130026757+0000");
    data.put("Createdby", "3");
    data.put("GroupUser",  "{1,2,3,4}");
    data.put("status", "active");

    String mapping = {"typename":{"properties":{
    "GroupName":{"type":"keyword"},
    "Createdby":{"type":"keyword"},
    "GroupUser":{"type":"keyword"},
    "UpdatedDateTime":{"keyword":"text"},
    "CreatedDateTime":{"keyword":"text"},
    "GroupId":{"type":"keyword"},
    "status":{"type":"keyword"}}}}

    client = new PreBuiltTransportClient(settings).addTransportAddresses(new TransportAddress(new InetSocketAddress(ipaddress, port)));

   client.admin().indices().prepareCreate("indexName").get(); 

    //inserting mapping
    client.admin().indices().preparePutMapping(indexName)
    .setType("typeName")
    .setSource(mapping, XContentType.JSON)
    .get();

    //inserting record
    IndexResponse response = client.prepareIndex(indexName, typeName).setSource(data).get();

现在我可以插入了。但是当我在 GroupName 中搜索 a 值时,结果为空。

瓦尔

not_analyzed已弃用,您需要keyword改用。

试试下面的这个映射,而不是:

String mapping = {
  "typename": {
    "properties": {
      "GroupName": {
        "type": "text",
        "fields": {
          "keyword": {
            "type": "keyword"
          }
        }
      },
      "Createdby": {
        "type": "text",
        "fields": {
          "keyword": {
            "type": "keyword"
          }
        }
      },
      "GroupUser": {
        "type": "text",
        "fields": {
          "keyword": {
            "type": "keyword"
          }
        }
      },
      "UpdatedDateTime": {
        "type": "date",
        "format": "yyyyMMddHHmmssSSSZ"
      },
      "CreatedDateTime": {
        "type": "date",
        "format": "yyyyMMddHHmmssSSSZ"
      },
      "GroupId": {
        "type": "text",
        "fields": {
          "keyword": {
            "type": "keyword"
          }
        }
      },
      "status": {
        "type": "text",
        "fields": {
          "keyword": {
            "type": "keyword"
          }
        }
      }
    }
  }
}

还要确保在插入数据之前放置映射,即

执行:

//inserting mapping

前:

//inserting record

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

映射中的not_analyzed被忽略

Spring Elasticsearch HashMap [String,String]映射值不能not_analyzed

Elasticsearch:根映射定义具有不受支持的参数索引:not_analyzed

elasticsearch not_analyzed不起作用

用于Elasticsearch的River Plugin Not_analyzed选项

弹性搜索中的“ index”:“ not_analyzed”

如何在spring-data-elasticsearch 3.0.0.RC2中使用@Field注释配置not_analyzed

在elasticsearch for kibana中有一个not_analyzed的字段

Elasticsearch-将字段从not_analyzed更改为分析

以not_analyzed进行映射后获得完全匹配

创建ElasticSearch动态模板以确保所有字段都设置为not_analyzed

elasticsearch在not_analyzed字段上不区分大小写的术语过滤器搜索

Lucene如何索引not_analyzed字段

在Nest 5.5.0中为属性设置not_analyzed

如何将 not_analyzed 应用于字段

使用传输客户端创建索引时,应如何指定对not_analyzed字段的分析

如何使用Logstash配置文件将Logstash中的字段设置为“ not_analyzed”

无法在Elasticsearch中更新映射

无法打开 Elasticsearch 动态映射

ElasticSearch-无法获取映射

Elasticsearch字段提升未在映射中显示

Elasticsearch:在映射中定义字段词汇

ES6映射中的所有对

无法在 Informatica 映射中捕获参数值

无法在Linux上使用ElasticSearch映射Logstash

Elasticsearch映射无法按预期工作

无法使用Django Haystack rebuild_index elasticsearch:“连接被拒绝”

无法将“{1, 2 ,3, 4, 5, 6}”转换为 list<int> C++?

无法加载JNA本机支持库Elasticsearch 6.x