我正在尝试搜索索引的所有字段上的字符串:
这是我的要求:
from elasticsearch import Elasticsearch
from pprint import pprint
# Connect to the elastic cluster
auth = ('Toto', 'Titi')
es=Elasticsearch("https://192.168.1.92:9200",verify_certs=False,http_auth=auth)
e1={'BARCODE': '366221700417', 'BRAND_MEDALS': ['Transparency'], 'BRAND_NAME': 'Avril', 'COMPOSITION': [{'INGREDIENT_GRADE': 'good', 'INGREDIENT_NAME': 'Aqua'}, {'INGREDIENT_GRADE': 'good', 'INGREDIENT_NAME': 'Citrus Aurantium Amara Water'}, {'INGREDIENT_GRADE': 'neutral', 'INGREDIENT_NAME': 'Sodium Cocoyl Glutamate'}, {'INGREDIENT_GRADE': 'allergene', 'INGREDIENT_NAME': 'Cocamidopropyl Betaine'}, {'INGREDIENT_GRADE': 'good', 'INGREDIENT_NAME': 'Glycerin'}, {'INGREDIENT_GRADE': 'neutral', 'INGREDIENT_NAME': 'Polyglyceryl-4 Caprate'}, {'INGREDIENT_GRADE': 'neutral', 'INGREDIENT_NAME': 'Sodium Chloride'}, {'INGREDIENT_GRADE': 'neutral', 'INGREDIENT_NAME': 'Xanthan Gum'}, {'INGREDIENT_GRADE': 'good', 'INGREDIENT_NAME': 'Aloe Barbadensis Leaf Juice Powder'}, {'INGREDIENT_GRADE': 'neutral', 'INGREDIENT_NAME': 'Sodium Benzoate'}, {'INGREDIENT_GRADE': 'allergene', 'INGREDIENT_NAME': 'Levulinic Acid'}, {'INGREDIENT_GRADE': 'neutral', 'INGREDIENT_NAME': 'Citric Acid'}, {'INGREDIENT_GRADE': 'neutral', 'INGREDIENT_NAME': 'Sodium Levulinate'}], 'DATASOURCE': 'avril 2019_02', 'FRONT_PICTURE': 'https://koalabourre.s3-eu-west-1.amazonaws.com/default_pic_76d3ec7a-f9f4-4c20-ba32-213e6ed02894.jpg', 'OVERVIEW': {'Allergene': 2, 'Avoid': 0, 'Danger': 0, 'Good': 4, 'Neutral': 7, 'Unknown': 0}, 'PRODUCT_CATEGORY': 'Soin Du Corps', 'PRODUCT_NAME': 'Base Lavante Neutre 2040 Ml - Certifiée Bio', 'PRODUCT_USAGE': ''}
res = es.index(index='product_json',doc_type='product',id=e1["BARCODE"],body=e1)
res= es.search(index='product_json',body={'query':{'match':{'BRAND_NAME':'avril'}}})
print(res)
res= es.search(index='product_json',body={'query':{'match':{"PRODUCT_NAME":'aavril'}}})
print(res)
res= es.search(index='product_json',body={'query':{'match':{"all":'aavril'}}})
print(res)
res= es.search(index='product_json',body={'query':{'multi_match': {'query': 'aavril'}}})
如何在所有字段上搜索字符串aavril?你知道吗
敬礼
有几种不同的方法:
使用多重匹配:
使用bool:
或者首选方法,在索引时,创建一个字段,将要搜索的所有字段串联起来,然后对该字段进行简单匹配。你知道吗
相关问题 更多 >
编程相关推荐