使用netstat -lntp来看看有侦听在网络某端口的进程。当然,也可以使用 lsof。

请教:ES如何通过 bool must match_phrase实现多词组保序查询?

Elasticsearch | 作者 pan7da | 发布于2019年01月08日 | 阅读数:3540

1. 测试文本为
  a. 中华人民共和国
  b. 共和国人民中华
  c. 中国人是华人,是共和国
  d. 中华大地,共有经济体和国家
2. 要求:用户输入 中华*共和国,得到 a
3. 诉求:我有如下语句,可以找到a,但是也匹配到了b,b是期望匹配到的。
curl -X GET "http://127.0.0.1:24100/nebula/... " -H 'Content-Type: application/json' -d '
{
    "query": {
        "bool": {
            "must": [
                {
                    "match_phrase": {
                        "description": "中华"
                    }
                },
                {
                    "match_phrase": {
                        "description": "共和国"
                    }
                }
            ]
        }
    }
}'
麻烦帮忙看下有没有什么方法可以做到只匹配 a,谢谢。
已邀请:

pan7da

赞同来自:

补充:分词器使用的 Standard。

God_lockin

赞同来自:

莫名其妙的格式都没了,凑合看吧
_search:
[
{
"_index": "testindex2",
"_type": "_doc",
"_id": "KIZfLWgBRJBziWO5luE4",
"_score": 1,
"_source": {
"name": "中华人民共和国"
}
}
,
{
"_index": "testindex2",
"_type": "_doc",
"_id": "KYZfLWgBRJBziWO5t-Gm",
"_score": 1,
"_source": {
"name": "共和国人民中华"
}
}
]
post:_search
{
"query": {
"match_phrase": {
"name": {
"query": "中华共和国",
"slop": 2
}
}
}
}
mappings
"mappings": {
"_doc": {
"properties": {
"name": {
"analyzer": "standard",
"type": "text"
}
}
}

pan7da

赞同来自:

@God_lockin 谢谢答复。
1. 不好意思,手抖,打少了一个字,应该是”b是不期望匹配到的“。
    在上面的测试集中,我只希望匹配得到a。
    另:”中华“ 和 ”共和国“ 中间的字符数不确定,且“中华”必须是一整个词,”共和国“必须是一整个词。
2. 你说的这个方法,不能保序,即:”中华“在前,”共和国“在后;slop设置为2,限制了"中华"和”共和国“之间的字符个数(当然可以通过增大slop匹配中间更多的字符,也会匹配到c,d)。
    总体意思是:1. 该方法不能保证“中华”是一整个词,”共和国“是一整个词;2. 这两个词不保序。
 
麻烦再帮忙看看还有其他方法不?谢谢。

God_lockin

赞同来自:

我这个query可以把B规避掉啊
中间不确定个数的字可以直接取个size/length填在slop里面就好了
post:_search
{
"query": {
"match_phrase": {
"name": {
"query": "中华共和国",
"slop": 2
}
}
}
}

--------

{
"took": 61,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"skipped": 0,
"failed": 0
},
"hits": {
"total": 1,
"max_score": 0.43598637,
"hits": [
{
"_index": "testindex",
"_type": "_doc",
"_id": "3r_xLWgBUWD2vdgF_-W3",
"_score": 0.43598637,
"_source": {
"name": "中华人民共和国"
}
}
]
}
}
get:_search
{
"took": 6,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"skipped": 0,
"failed": 0
},
"hits": {
"total": 2,
"max_score": 1,
"hits": [
{
"_index": "testindex",
"_type": "_doc",
"_id": "3r_xLWgBUWD2vdgF_-W3",
"_score": 1,
"_source": {
"name": "中华人民共和国"
}
},
{
"_index": "testindex",
"_type": "_doc",
"_id": "37_yLWgBUWD2vdgFJOWb",
"_score": 1,
"_source": {
"name": "共和国人民中华"
}
}
]
}
}

要回复问题请先登录注册