爬蟲及ES查詢分析器搜索指令

用戶代理模塊
https://github.com/hellysmile/fake-useragent
http代理 西刺代理

http://www.xicidaili.com/

elasticsearch-dsl-py

可以借助接口幫我們分詞
GET _analyze
{
"analyzer": "ik_smart",
"text": "python工程師"
}
es搜索
jobbole:index
article:type
1、match 會對輸入的查詢進行分詞
GET jobbole/article/_search
{
"query" : {
"match " : { "content" : "27" }
}
}
2、term 不會對輸入查詢進行分詞,進行全量匹配,但可以傳遞數(shù)據(jù)進行匹配
GET jobbole/article/_search
{
"query" : {
//"term" : { "content" : "27" }
"term" : { "content" : ["27","29","30"] }
},
"from":1,
"size":3
}
3、match_all 全查,{}為空
GET jobbole/article/_search
{
"query" : {
"match_all" : {}
}
}
3、match_phrase 會將查詢先分詞,查詢結果包含全部分詞才行,slop標示分詞之間的距離,小于就不行
GET jobbole/article/_search
{
"query" : {
"match_phrase" : {
"content": {
"query": "python視頻",
"slop":3
}}
}
}
4、multi_match 多個字段中,匹配查詢條件
GET jobbole/article/_search
{
"query" : {
"multi_match" : {
"query": "python",
"fields": ["content","url"]
}
}
}
5、返回指定字段,前提是mapping中該字段的 store屬性為true
GET jobbole/article/_search
{
"query" : {
"match" : {
"content": "python"
}
},
"stored_fields": ["content"]
}
6、還有sort之類的就不列了,看文檔去
7、通配符查詢
GET jobbole/article/_search
{
"query" : {
"wildcard" : {
"content": {"value": "pyth*n","boost": 2}
}
}
}
8、組合查詢 bool查詢
GET jobbole/article/_search
{
"query" : {
"bool": {
"must": [
{"match": {
"FIELD": "TEXT"
}}
],
"filter": {"term": {
"FIELD": "VALUE"
}},
"must_not": [
{}
],
"should": [
{}
]
}
}
}
9、高量查詢 默認 高亮詞會用<em>和</em>包圍,你可以通過pre_tags 和 post_tags修改它:
GET jobbole/article/_search
{
"query" : {
"match": { "content": "小姐姐" }
},
"highlight" : {
"pre_tags" : ["<tag1>", "<tag2>"],
"post_tags" : ["</tag1>", "</tag2>"],
"fields" : {
"content" : {"type" : "plain"}
}
}
}

10、聯(lián)想詞(Suggesters)
POST jobbole/article/_search
{
"query" : {
"match": {
"content": "。。。"
}
},
"suggest" : {
"my-suggestion" : {
"text" : "",
"term" : {
"field" : "content"
}
}
}
}

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯(lián)系作者
【社區(qū)內容提示】社區(qū)部分內容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發(fā)布,文章內容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內容

友情鏈接更多精彩內容