ES ik+pinyin

 

最近要做ES  没办法 研究

curl 版本

正确 添加分词索引
curl -XPOST http://127.0.0.1:9200/test/test/_mapping -d'{
"test": {
"_all": {
"analyzer": "ik_max_word",
"search_analyzer": "ik_max_word",
"term_vector": "no",
"store": "false"
},
"properties": {
"content": {
"type": "text",
"store": "no",
"term_vector": "with_positions_offsets",
"analyzer": "ik_max_word",
"search_analyzer": "ik_max_word",
"include_in_all": "true",
"boost": 8
}
}
}
}'

curl -XGET "http://127.0.0.1:9200/test/_mapping?pretty"

查看map

添加拼音分词配置

    • ####拼音使用//先关闭 已存在索引curl -XPOST 127.0.0.1.26:9200/test/_close -d'{}'//设置分词器配置curl -XPUT 127.0.0.1:9200/test/_settings -d'{"index" : { "analysis" : { "analyzer" : { "pinyin_analyzer" : { "tokenizer" : "my_pinyin", "filter" : ["word_delimiter","nGram"] } }, "tokenizer" : { "my_pinyin" : { "type" : "pinyin", "first_letter" : "prefix", "padding_char" : " " } } } }}'//打开索引curl -XPOST http://127.0.0.1:9200/test/_open -d'{}'
    • //更新map
      curl -XPOST 127.0.0.1 :9200/test/test/_mapping -d'{
      "test": {
      "properties": {
      "name": {
      "type": "text",
      "store": "no",
      "term_vector": "with_positions_offsets",
      "analyzer": "pinyin_analyzer",
      "boost": 10
      }
      }
      }
      }'
      //添加数据
      curl -XPOST 127.0.0.1:9200/test/test -d'{
      "name":"刘德华"
      }'
      //拼音查询
      curl -XGET 127.0.0.1:9200/test/test/_search -d'{
      "query": {"match": {
      "name": "l d hua"
      }}
      }'
$params = [
    'index' => 'index',  //索引名(相当于mysql的数据库)
    'type'  => 'index_type',
    'body'  =>  [
        'my_type' => [
            'properties'    =>[
                'contents'   =>[
                    'type'  => 'text',
                    'store'  => 'no',
                    'term_vector'  => 'with_positions_offsets',
                    'analyzer'  => 'ik_max_word',
                    'search_analyzer'  => 'ik_max_word',
                    'include_in_all'  => 'true',
                    'boost'  => 8,
                ]
            ]
        ]
    ]
];
$client->indices()->putMapping($params);

拼音设置 见curl版本



加数据


$userList = [
    [
        'id' => rand(1000, 9999),
        'question' => rand(1,9),
        'answer' => rand(1,9),
        'tag' => 'zzz',
        'upt' => time(),
        'content' => '中国馆:各地校车将享最高路权吗',
    ],[
        'id' => rand(1000, 9999),
        'question' => rand(1,9),
        'answer' => rand(1,9),
        'tag' => 'zzz',
        'upt' => time(),
        'content' => '公安部:各地校车将享最高路权吗',
    ],[
        'id' => rand(1000, 9999),
        'question' => rand(1,9),
        'answer' => rand(1,9),
        'tag' => 'zzz',
        'upt' => time(),
        'content' => '中韩渔警冲突调查:韩警平均每天扣1艘中国渔船',
    ],[
        'id' => rand(1000, 9999),
        'question' => rand(1,9),
        'answer' => rand(1,9),
        'tag' => 'zzz',
        'upt' => time(),
        'content' => '公安部:各地校车将享最高路权吗',
    ],
];
foreach($userList as $value){
    $params['body'][] = [
        'index' => [
            '_index' => 'index',
            '_type' => 'my_type',
            '_id'  =>$value['id']
        ]
    ];
    $params['body'][] = [
        'question' => $value['question'],
        'answer' => $value['answer'],
        'tag' => $value['tag'],
        'upt' => $value['upt'],
        'content' => $value['content'],
    ];
}
$responses = $client->bulk($params);

匹配 多字段内容

$params = [
    'index' => 'index',
    'type' => 'my_type',
    'body'=> [
        'query'=> [
            'multi_match'=> [
                'query' => $keyword,
                'fields'=> [
                    'content',
                ],
            ],
            //'match_all'=> new \stdClass()
        ],
    ]
];

//修改配置

$params = [
    'index' => 'my_index',
    'body' => [
        'settings' => [
            'number_of_replicas' => 0,
            'refresh_interval' => -1
        ]
    ]
];

$response = $client->indices()->putSettings($params);

详细参考

Elasticsearch: 权威指南》

《基于elasticsearch suggester的中文检索建议实现》

ElasticSearch 6.x 学习笔记:4.IK分词器插件》

https://www.jianshu.com/p/eb30eee13923

https://www.cnblogs.com/life_lt/p/6122767.html

https://www.cnblogs.com/bonelee/p/6105394.html

https://www.elastic.co/guide/cn/elasticsearch/guide/current/multi-match-query.html

https://www.jianshu.com/p/a2837f487de6

https://elasticsearch.cn/article/142

https://www.cnblogs.com/xing901022/p/5910139.html 分词 拼音详细教程 str废弃改用text

https://www.elastic.co/guide/en/elasticsearch/client/php-api/6.0/ElasticsearchPHP_Endpoints.html#Elasticsearch_Client

https://www.elastic.co/guide/cn/elasticsearch/guide/current/mapping-geo-shapes.html


es 官网搜索 phpapi







  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值