elasticsearch-kibanna 查询札记

来源:互联网 发布:php 输出文本文件乱码 编辑:程序博客网 时间:2024/06/01 09:52
查询xiu索引所有数据
GET xiu/_search
{
  "query": {
    "match_all": {}
  }
}

GET xiu/selection/_search?_source=productSn
{
  "query": {
    "bool": {
      "must": [
        {
          "bool": {
            "should": [
              {
                "term": {
                  "brandCode": {
                    "value": "IT0089",
                    "boost": 1
                  }
                }
              },
              {
                "term": {
                  "brandCode": {
                    "value": "IT0927",
                    "boost": 1
                  }
                }
              }
            ],
            "disable_coord": false,
            "adjust_pure_negative": true,
            "boost": 1
          }
        }
      ],
      "disable_coord": false,
      "adjust_pure_negative": true,
      "boost": 1
    }
  }
}
PUT /index
DELETE /index
GET /index/_mapping
POST /index/fulltext/_mapping
{
  "fulltext": {
    "_all": {
      "analyzer": "ik_smart",
      "search_analyzer": "ik_max_word",
      "term_vector": "no",
      "store": "false"
    },
    "properties": {
      "content": {
        "type": "text",
        "analyzer": "ik_smart",
        "search_analyzer": "ik_max_word",
        "include_in_all": "true",
        "boost": 8
      }
    }
  }
}
POST /index/fulltext/1
{"content":"美国留给伊拉克的是个烂摊子吗"}

POST /index/fulltext/2
{"content":"公安部:各地校车将享最高路权"}

POST /index/fulltext/3
{"content":"中韩渔警冲突调查:韩警平均每天扣1艘中国渔船"}

POST /index/fulltext/4
{"content":"中国驻洛杉矶领事馆遭亚裔男子枪击 嫌犯已自首"}

POST /index/fulltext/_search
{
  "query": {
    "match": {
      "content": "美国"
    }
  },
  "highlight": {
    "pre_tags": [
      "<tag1>",
      "<tag2>"
    ],
    "post_tags": [
      "</tag1>",
      "</tag2>"
    ],
    "fields": {
      "content": {}
    }
  }
}

GET /index/_mapping

GET /xiu/_analyze?analyzer=ik_smart
{
  "text":"走秀网科技有限公司"
}

GET /xiu/_analyze?analyzer=ik_max_word
{
  "text":"中华人名共和国"
}

GET /xiu/_analyze?analyzer=standard&text='中华人名共和国'


PUT index
{
  "settings": {
    "number_of_shards": 3,
    "number_of_replicas": 0
  }
}


PUT xiu6
{
  "index": {
    "analysis": {
      "analyzer": {
        "ik_pinyin_analyzer": {
          "type": "custom",
          "tokenizer": "ik_smart",
          "filter": [
            "my_pinyin",
            "word_delimiter"
          ]
        }
      },
      "filter": {
        "my_pinyin": {
          "type": "pinyin",
          "first_letter": "prefix",
          "padding_char": " "
        }
      }
    }
  }
}

PUT blog/article

GET blog/_mapping

PUT blog/article/_mapping
{
  "properties": {
    "id":{
      "type":"long"
    },
    "content":{
      "type": "text",
      "analyzer": "ik_max_word",
      "search_analyzer": "ik_max_word"
    },
    "postdate":{
      "type": "date",
      "format": "yyyy-MM-dd HH:mm:ss || yyyy-MM-dd || epoch_millis"
    },
    "price":{
      "type": "double"
    }
  }
 
}


GET blog/_search

GET blog/_search
{
  "query": {
    "match_all": {}
  }
}

GET blog/_analyze?analyzer=ik_max_word
{
  "text": "title"
}

GET blog/_search
{
  "query": {
    "term": {
      "title": {
        "value": "java"
      }
    }
  }
}

GET xiu/_analyze?analyzer=ik_max_word
{
  "text": "武汉市长江大桥"
}

GET xiu/_analyze?analyzer=pinyin
{
  "text": "张学友"
}



GET xiu/_analyze?analyzer=ik_smart
{
  "text":"武汉市长江大桥"
}


GET xiu/selection/_search
{
  "from": 0,
  "size": 20,
  "query": {
    "term": {
      "brandCode": {
        "value": "IT0389"
      }
    }
  }
}

GET xiu/selection/_search
{
  "query": {
    "range": {
      "createTime": {
        "format": "yyyy-MM-dd HH:mm:ss",
        "gte": "2017-05-10 00:00:00",
        "lte": "2017-09-10 00:00:00"
      }
    }
  }
}


GET xiu/selection/_search?_source=taxFreePrice,showPrice
{
  "query": {
    "term": {
      "brandCode": {
        "value": "IT0007"
      }
    }
  }
}

GET xiu/selection/_search
{
  "query": {
      "must": [
        {
          "range": {
            "createTime": {
              "from": "2017-05-10 00:00:00",
              "to": "2017-08-10 00:00:00",
              "include_lower": true,
              "include_upper": true,
              "boost": 1
            }
          }
        }
      ]
  }
}


GET xiu/selection/_search?_source=brandCode,onsaleState
{
  "query": {
    "bool": {
      "must": [
        {
          "bool": {
            "should": [
              {
                "match": {
                  "brandCode": {
                    "query": "IT0089",
                    "operator": "OR",
                    "prefix_length": 0,
                    "max_expansions": 50,
                    "fuzzy_transpositions": true,
                    "lenient": false,
                    "zero_terms_query": "NONE",
                    "boost": 1
                  }
                }
              },
              {
                "match": {
                  "brandCode": {
                    "query": "IT0927",
                    "operator": "OR",
                    "prefix_length": 0,
                    "max_expansions": 50,
                    "fuzzy_transpositions": true,
                    "lenient": false,
                    "zero_terms_query": "NONE",
                    "boost": 1
                  }
                }
              }
            ],
            "disable_coord": false,
            "adjust_pure_negative": true,
            "boost": 1
          }
        },
        {
          "match": {
            "onsaleState": {
              "query": 1,
              "operator": "OR",
              "prefix_length": 0,
              "max_expansions": 50,
              "fuzzy_transpositions": true,
              "lenient": false,
              "zero_terms_query": "NONE",
              "boost": 1
            }
          }
        }
      ]
    }
  }
}

GET xiu/selection/_search
{
  "query": {
    "bool": {
      "must": [
        {
          "match": {
            "onsaleState": {
              "query": 1,
              "operator": "OR",
              "prefix_length": 0,
              "max_expansions": 50,
              "fuzzy_transpositions": true,
              "lenient": false,
              "zero_terms_query": "NONE",
              "boost": 1
            }
          }
        }
      ],
      "disable_coord": false,
      "adjust_pure_negative": true,
      "boost": 1
    }
  }
}

GET xiu/selection/_search
{
  "query": {
    "bool": {
      "disable_coord": false,
      "adjust_pure_negative": true,
      "boost": 1
    }
  }
}

GET xiu/selection/_search
{
  "query": {
    "bool": {
      "must": [
        {
          "bool": {
            "should": [
              {
                "match": {
                  "brandCode": {
                    "query": "IT0089",
                    "operator": "OR",
                    "prefix_length": 0,
                    "max_expansions": 50,
                    "fuzzy_transpositions": true,
                    "lenient": false,
                    "zero_terms_query": "NONE",
                    "boost": 1
                  }
                }
              },
              {
                "match": {
                  "brandCode": {
                    "query": "IT0927",
                    "operator": "OR",
                    "prefix_length": 0,
                    "max_expansions": 50,
                    "fuzzy_transpositions": true,
                    "lenient": false,
                    "zero_terms_query": "NONE",
                    "boost": 1
                  }
                }
              }
            ],
            "disable_coord": false,
            "adjust_pure_negative": true,
            "boost": 1
          }
        },
        {
          "bool": {
            "should": [
              {
                "match": {
                  "spaceFlag": {
                    "query": "香港",
                    "operator": "OR",
                    "prefix_length": 0,
                    "max_expansions": 50,
                    "fuzzy_transpositions": true,
                    "lenient": false,
                    "zero_terms_query": "NONE",
                    "boost": 1
                  }
                }
              }
            ],
            "disable_coord": false,
            "adjust_pure_negative": true,
            "boost": 1
          }
        },
        {
          "bool": {
            "should": [
              {
                "match": {
                  "oneClassCode": {
                    "query": "1",
                    "operator": "OR",
                    "prefix_length": 0,
                    "max_expansions": 50,
                    "fuzzy_transpositions": true,
                    "lenient": false,
                    "zero_terms_query": "NONE",
                    "boost": 1
                  }
                }
              },
              {
                "match": {
                  "oneClassCode": {
                    "query": "7",
                    "operator": "OR",
                    "prefix_length": 0,
                    "max_expansions": 50,
                    "fuzzy_transpositions": true,
                    "lenient": false,
                    "zero_terms_query": "NONE",
                    "boost": 1
                  }
                }
              },
              {
                "match": {
                  "oneClassCode": {
                    "query": "8",
                    "operator": "OR",
                    "prefix_length": 0,
                    "max_expansions": 50,
                    "fuzzy_transpositions": true,
                    "lenient": false,
                    "zero_terms_query": "NONE",
                    "boost": 1
                  }
                }
              }
            ],
            "disable_coord": false,
            "adjust_pure_negative": true,
            "boost": 1
          }
        },
        {
          "range": {
            "showPrice": {
              "from": 100,
              "to": 3000,
              "include_lower": true,
              "include_upper": true,
              "boost": 1
            }
          }
        },
        {
          "match": {
            "onsaleState": {
              "query": 1,
              "operator": "OR",
              "prefix_length": 0,
              "max_expansions": 50,
              "fuzzy_transpositions": true,
              "lenient": false,
              "zero_terms_query": "NONE",
              "boost": 1
            }
          }
        },
        {
          "range": {
            "createTime": {
              "from": "2017-09-01 01:01:01",
              "to": "2017-09-09 01:01:01",
              "include_lower": true,
              "include_upper": true,
              "boost": 1
            }
          }
        }
      ],
      "disable_coord": false,
      "adjust_pure_negative": true,
      "boost": 1
    }
  }
}



GET xiu/selection/_search
{
  "query": {
    "multi_match": {
      "query": "鞋",
      "fields": [
        "brandChName^1.0",
        "brandEnName^1.0",
        "productKeywords^1.0",
        "productName^1.0",
        "productSn^1.0"
      ],
      
      "type": "best_fields",
      "operator": "OR",
      "slop": 0,
      "prefix_length": 0,
      "max_expansions": 50,
      "lenient": false,
      "zero_terms_query": "NONE",
      "boost": 1
    }
  }
}

GET medcl/_settings

PUT /medcl/
{
  "index": {
    "analysis": {
      "analyzer": {
        "ik_pinyin_analyzer": {
          "type": "custom",
          "tokenizer": "ik_smart",
          "filter": [
            "my_pinyin",
            "word_delimiter"
          ]
        }
      },
      "filter": {
        "my_pinyin": {
          "type": "pinyin",
          "first_letter": "prefix",
          "padding_char": " "
        }
      }
    }
  }
}

POST /medcl/folks/_mapping
{
  "folks": {
    "properties": {
      "name": {
        "type": "keyword",
        "fields": {
          "pinyin": {
            "type": "text",
            "store": "no",
            "term_vector": "with_positions_offsets",
            "analyzer": "ik_pinyin_analyzer",
            "boost": 10
          }
        }
      }
    }
  }
}

GET /medcl/folks/_mapping

POST /medcl/folks/andy
{
  "name": "刘德华"
}

POST /medcl/folks/tina
{
  "name": "中华人民共和国国歌"
}


POST /medcl/folks/_search?q=name.pinyin:liu

POST /medcl/folks/_search?q=name.pinyin:de

POST /medcl/folks/_search?q=name.pinyin:hua

POST /medcl/folks/_search?q=name.pinyin:ldh

POST /medcl/_search?pretty
{
  "query": {
    "match": {
      "name.pinyin": "国歌"
    }
  },
  "highlight": {
    "fields": {
      "name.pinyin": {}
    }
  }
}

POST /medcl/_search?pretty
{
  "query": {
    "match": {
      "name.pinyin": "zhonghua"
    }
  },
  "highlight": {
    "fields": {
      "name.pinyin": {}
    }
  }
}

原创粉丝点击