#!/usr/bin/env python
# -*- coding: utf-8 -*- """ pass
""" import os
import sys
import jieba sys.path.append(os.path.dirname(os.path.split(os.path.realpath(__file__))[0])) from elasticsearch import Elasticsearch
from conf.settings import FAQ_ES_CONF # [{'host': '192.168.7.173', 'port': 9200}] es_ser = Elasticsearch(FAQ_ES_CONF) es_ser.indices.delete(index='customer', ignore=404) es_ser.indices.create(index='customer', ignore=400) body={"properties":{'about': {'type': 'string'},
'name': {'type': 'string'},
'age': {'type': 'integer'},
'score': {'type': 'integer'},
'company': {'type': 'string', 'index': 'not_analyzed'},
'interests': {'type': 'string'},
'timestamp': {'type': 'date'},
'id': {'type': 'integer'}}} es_ser.indices.put_mapping(index='customer', doc_type='round_FAQ2', body=body) es_ser.index(index='customer',
doc_type='round_FAQ2',
id=1,
body={"name":"wulangzhou",
"age": 25,
"score": [85,75,95],
"about": jieba.lcut('i like think deep'),
"company": 'zhangyue',
"interests": ["music"],
"timestamp": ''}) es_ser.index(index='customer',
doc_type='round_FAQ2',
id=2,
body={"name":"yanweihong",
"age": 28,
"about": jieba.lcut('i like exercise more'),
"score": [90,85,77],
"company": 'zhangyue',
"interests": ["forestry", 'i', 'like'],
"timestamp": ''}) es_ser.index(index='customer',
doc_type='round_FAQ2',
id=3,
body={"name":"liumin",
"age": 28,
"about": jieba.lcut('i like cat'),
"score": [80, 80, 80, 80],
"company": 'jindong',
"weight": 85,
"interests": ['game'],
"timestamp": ''}) import time
time.sleep(1) body={'query': {'multi_match': {'query': 'i like cat' ,
'fields': ['about', 'interests'],
'type': 'most_fields',}}}
#'tie_breaker': 0.2}}}

body={'query': {'match_phrase': {'about': 'i like'}}}
body={'query': {'range': {'age': {'gte': 18, 'lte': 35}}}}
body={'query': {'match_all': {}}}

body={'query': {'terms': {'age': [22, 20]}}}

body={'query': {'exists': {'field': 'weight'}}}

for sources in es_ser.search(index='customer', doc_type='round_FAQ2', body=body)['hits']['hits']:
for k, v in sources.items():
print k, v
print '' '''
http://www.tuicool.com/articles/uAbmuaU
match_phrase 可以看about 字段,如果该字段是string 且被设置为默认分词,可以看做是‘query_str‘ in ‘match_string’(查询字符和匹配字符都不分词进行匹配)?
match 可以看about 字段,表示 query_str分词后中的每一个词,与match_string分词后中的所有词,看能匹配到几个(查询字符和匹配字符都进行分词匹配)。
term 与 match_phrase 稍微有点区别 ‘query_str‘ == ‘match_string’ ?) (不进行分词的匹配)
multi_match 如果搭配 most_fields 表示fields中的所有字段,分词后尽量匹配多的词的和(不要带tie_breaker)
如果搭配 best_fields 表示完全匹配的分值最高 比如 i like cat 如果全部匹配到了则分高(带tie_breaker)
terms 与term 类似
bool 当我们需要and or 查询的时候,可以用 bool 查询,查询条件可以嵌套 { "bool" : { "must" : [], "should" : [], "must_not" : [], } }
def get_analyze_body(**kargs):
""" 将查询条件转成特殊的查询参数
"""
from faq.doc_idf import get_phrases_rate question = kargs.get('question')
if question and isinstance(question, str):
question = question.decode('utf-8') question = replace_string(question) question_args = get_right_phrases(filter_phrases(jieba_cut(question)))
channel_num_arg = kargs.get('channel_num')
version_arg = kargs.get('version') question_arg_rate = get_phrases_rate(question_args) should = []
for question_arg, rate in question_arg_rate.items():
should.append({'match_phrase': {'question': {'query': question_arg,
'boost': 10 * rate}}}) must_channel_num = []
must_channel_num.append({'match_phrase': {'channel_num': {'query': -1,
'boost': 1}}})
if channel_num_arg:
must_channel_num.append({'match_phrase': {'channel_num': {'query': int(channel_num_arg),
'boost': 1.5}}}) must_version = []
must_version.append({'match_phrase': {'version': {'query': -1,
'boost': 1}}})
if version_arg:
must_version.append({'match_phrase': {'version': {'query': int(version_arg),
'boost': 1.5}}}) return {'query': {'bool': {'should': should,
'must': [{'bool': {'should': must_channel_num}},
{'bool': {'should': must_version}}]}},
'min_score': 1}
 

elastic_search 指令的更多相关文章

  1. iOS逆向工程之Hopper中的ARM指令

    虽然前段时间ARM被日本软银收购了,但是科技是无国界的,所以呢ARM相关知识该学的学.现在看ARM指令集还是倍感亲切的,毕竟大学里开了ARM这门课,并且做了不少的实验,当时自我感觉ARM这门课学的还是 ...

  2. 步入angularjs directive(指令)--点击按钮加入loading状态

    今天我终于鼓起勇气写自己的博客了,激动与害怕并存,希望大家能多多批评指导,如果能够帮助大家,也希望大家点个赞!! 用angularjs 工作也有段时间了,总体感觉最有挑战性的还是指令,因为没有指令的a ...

  3. Git小技巧 - 指令别名及使用Beyond Compare作为差异比较工具

    前言 本文主要写给使用命令行来操作Git的用户,用于提高Git使用的效率.至于使用命令还是GUI(Tortoise Git或VS的Git插件)就不在此讨论了,大家根据自己的的喜好选择就好.我个人是比较 ...

  4. 浅谈JSP中include指令与include动作标识的区别

    JSP中主要包含三大指令,分别是page,include,taglib.本篇主要提及include指令. include指令使用格式:<%@ include file="文件的绝对路径 ...

  5. [Django]用户权限学习系列之User权限基本操作指令

    针对Django 后台自带的用户管理系统,虽说感觉还可以,但是为了方便用户一些操作,特别设计自定义的用户权限管理系统. 在制作权限页面前,首先需要了解权限和用户配置权限的指令,上章讲到权限的添加,删除 ...

  6. 机器指令翻译成 JavaScript —— No.5 指令变化

    上一篇,我们通过内置解释器的方案,解决任意跳转的问题.同时,也提到另一个问题:如果指令发生变化,又该如何应对. 指令自改 如果指令加载到 RAM 中,那就和普通数据一样,也是可以随意修改的.然而,对应 ...

  7. ARM的栈指令

    ARM的指令系统中关于栈指令的内容比较容易引起迷惑,这是因为准确描述一个栈的特点需要两个参数: 栈地址的增长方向:ARM将向高地址增长的栈称为递增栈(Descendent Stack),将向低地址增长 ...

  8. IL指令详细表

    名称 说明 Add 将两个值相加并将结果推送到计算堆栈上. Add.Ovf 将两个整数相加,执行溢出检查,并且将结果推送到计算堆栈上. Add.Ovf.Un 将两个无符号整数值相加,执行溢出检查,并且 ...

  9. Angular学习-指令入门

    1.指令的定义 从用户的角度来看,指令就是在应用的模板中使用的自定义HTML标签.指令可以很简单,也可以很复杂.AngularJS的HTML编译器会解析指令,增强模板的功能.也是组件化未来的发展趋势, ...

随机推荐

  1. Exception in thread "main" redis.clients.jedis.exceptions.JedisDataException

    这个版本默认是开启了保护模式,进入redis的文件夹下的src 输入(前提是得开启redis服务): ./redis-cli config set protected-mode "no&qu ...

  2. (转帖) 为Docker容器指定自定义网段的固定IP/静态IP地址

    作者:雨水,日期:2016-04-09  CSDN博客: http://blog.csdn.net/gobitan 摘要:Docker容器运行的时候默认会自动分配一个默认网桥所在网段的IP地址.但很多 ...

  3. jmeter-对响应数据进行unicode转码

    1,请求接口成功后,返回数据为unicode编码,查看不方便

  4. 新浪云连接数据库php

    一般数据库连接$con = mysql_connect("localhost", "root", ""); 而新浪云共享数据库 <?p ...

  5. Microsoft's OWIN implementation, the Katana project

    参考: https://github.com/aspnet/AspNetKatana/ https://github.com/aspnet/AspNetKatana/wiki/Roadmap

  6. [spring]Bean注入——在XML中配置

    Bean注入的方式有两种: 一.在XML中配置 属性注入 构造函数注入 工厂方法注入 二.使用注解的方式注入@Autowired,@Resource,@Required 本文首先讲解在XML中配置的注 ...

  7. 【程序员笔试面试必会——排序①】Python实现 冒泡排序、选择排序、插入排序、归并排序、快速排序、堆排序、希尔排序

    最近在准备笔试题和面试题,把学到的东西整理出来,一来是给自己留个笔记,二来是帮助大家学习. 题目: 给定一个int数组A及数组的大小n,请返回排序后的数组. 测试样例:  输入:[1,2,3,5,2, ...

  8. Android Studio 3.0 及个版本下载和 gradle 各版本下载

    Android Studio 3.0 下载地址: 链接:http://pan.baidu.com/s/1jHVuOQi 密码:3pd0 Android Studio 3.0 包含了三大主要功能: 一套 ...

  9. ArcMap加载在线地图

    SimpleGIS 小小的SimpleGIS除了提供6大地图让人喜爱之外,更有其他的能耐同样让你爱不释手. 功能1:作为出图底图地图提供商中Bing.天地图两家提供的地图是无偏移的地图,所以可直接应用 ...

  10. StringUtils.isNumeric()的特殊点

    String str = "-1"; StringUtils.isNumeric(str) 返回的是false StringUtils.isNumeric()方法在判断字符串是否是 ...