这是json:
{
"took": 3,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 2,
"max_score": 1,
"hits": [
{
"_index": "testing",
"_type": "skills",
"_id": "AV9FMnRfkEZ90S4dhzF6",
"_score": 1,
"_source": {
"skill": "java"
}
}
,
{
"_index": "testing",
"_type": "skills",
"_id": "AV9FM777kEZ90S4dhzF7",
"_score": 1,
"_source": {
"skill": "c language"
}
}
]
}
}我有两个薪酬,我需要获得部分和准确的匹配技巧。
部分匹配:
假设如果我给出"c“,那么我就会得到"c语言”的结果。
输入:C -> c++语言
完全匹配:
假设如果我给出"java“,那么我就会得到结果"java”的技巧。
输入: java -> java
发布于 2017-10-22 18:54:44
尝尝这个。通过以下方式定义您的映射:
PUT index
{
"mappings": {
"type": {
"properties": {
"skill": {
"type": "string",
"index" : "analyzed",
"fields": {
"keyword": {
"type": "string",
"index" : "not_analyzed"
}
}
}
}
}
}
}与上述命令等效的卷曲:
curl -XPUT localhost:9200/index -d '
{
"mappings": {
"type": {
"properties": {
"skill": {
"type": "string",
"index" : "analyzed",
"fields": {
"keyword": {
"type": "string",
"index" : "not_analyzed"
}
}
}
}
}
}
}'增加文件:
POST index/type
{
"skill":"c language"
}
POST index/type
{
"skill":"java"
}与上述命令等效的CURL:
curl -XPOST localhost:9200/index/type -d '
{
"skill":"c language"
}'
curl -XPOST localhost:9200/index/type -d '
{
"skill":"java"
}'搜索你的文件:
部分匹配:
GET index/_search
{
"query": {
"match": {
"skill": "c"
}
}
}完全匹配:
GET index/_search
{
"query": {
"term": {
"skill.keyword": "java"
}
}
}与上述命令等效的CURL:
curl -XGET localhost:9200/index/_search -d '
{
"query": {
"match": {
"skill": "c"
}
}
}'
curl -XGET localhost:9200/index/_search -d '
{
"query": {
"term": {
"skill.keyword": "java"
}
}
}'https://stackoverflow.com/questions/46877425
复制相似问题