2016-12-03 3 views
0

J'ai essayé vraiment dur mais luttant pour obtenir ce droit. En fait, dans ma cartographie d'index, tous mes champs sont des chaînes de caractères. par exemplerecherche élastique requête Python DSL sur les types de chaînes

{"ind_ecue_fin_ult1":{"mappings":{"ind_ecue_fin_ult1":{"properties":{"age":{"type":"string"},"altaDiff":{"type":"string"},"antiguedad":{"type":"string"},"canal_entrada":{"type":"string"},"cod_prov":{"type":"string"},"conyuemp":{"type":"string"},"empIndex":{"type":"string"},"fecDiff":{"type":"string"},"gender":{"type":"string"},"ind_actividad_cliente":{"type":"string"},"indext":{"type":"string"},"indfall":{"type":"string"},"indrel":{"type":"string"},"indrel_1mes":{"type":"string"},"indresi":{"type":"string"},"nomprov":{"type":"string"},"nuevo":{"type":"string"},"others":{"type":"string"},"renta":{"type":"string"},"residence":{"type":"string"},"segmento":{"type":"string"},"tiprel_1mes":{"type":"string"},"wt":{"type":"double"}}}}}} 

Je l'aide du client pour ElasticSearch ont généré la requête suivante python:

{'query': {'bool': {'minimum_should_match': 5, 
    'should': [{'boost': 4, 'terms': {'age': '1'}}, 
    {'boost': 3, 'terms': {'antiguedad': '0.0'}}, 
    {'boost': 3.5, 'terms': {'indrel': '1'}}, 
    {'boost': 3, 'terms': {'indrel_1mes': '1'}}, 
    {'boost': 2, 'terms': {'tiprel_1mes': 'A'}}, 
    {'boost': 3, 'terms': {'indresi': 'S'}}, 
    {'boost': 2.5, 'terms': {'indext': 'N'}}, 
    {'boost': 2, 'terms': {'conyuemp': 'DEF'}}, 
    {'boost': 2, 'terms': {'canal_entrada': 'KHL'}}, 
    {'boost': 1.5, 'terms': {'indfall': 'N'}}, 
    {'boost': 1.5, 'terms': {'cod_prov': '28'}}, 
    {'boost': 2, 'terms': {'nomprov': 'MALAGA'}}, 
    {'boost': 1.5, 'terms': {'ind_actividad_cliente': '1'}}, 
    {'boost': 4, 'terms': {'renta': '1'}}, 
    {'boost': 2.5, 'terms': {'segmento': '02 - PARTICULARES'}}, 
    {'range': {'wt': {'boost': 5.0, 'gte': 0.4, 'lte': 0.525}}}]}}} 

Cependant, je reçois cette exception même si je tente sur une période de tableau dans « should »:

curl -XPOST "htturl -XPOST "http://localhost:9200/ind_ahor_fin_ult1/_search" -d' 
{"query": {"bool": {"minimum_should_match": 5, 
    "should": [{"terms": {"renta": "1"},"boost": 4}]}}}' 

{"error":{"root_cause":[{"type":"query_parsing_exception","reason":"[terms] query does not support [renta]","index":"ind_ahor_fin_ult1","line":3,"col":35}],"type":"search_phase_execution_exception","reason":"all shards failed","phase":"query","grouped":true,"failed_shards":[{"shard":0,"index":"ind_ahor_fin_ult1","node":"j20MAn_OQ9eRyNsrjf1MRQ","reason":{"type":"query_parsing_exception","reason":"[terms] query does not support [renta]","index":"ind_ahor_fin_ult1","line":3,"col":35}}]},"status":400} 

aidez s'il vous plaît. TIA.

+0

la requête de gamme fonctionne bien si, juste que ces requêtes de type chaîne isnt –

+0

boucle -XPOST "http: // localhost: 9200/ind_ahor_fin_ult1/_search" -d » { "requête": { "bool": { "devrait": {"match": {"segmento": "02 - PARTICULARES"}}, "boost": 1}}} ', lemme voir si je peux coudre le tableau aussi dans –

+0

curl -XPOST "http : // localhost: 9200/ind_ahor_fin_ult1/_search » -d » { "requête": { "bool": { "devrait": [{ "match": { "segmento": "02 - PARTICULARES" }}, {"match": {"renta": "1"}} ] } } } 'Cela a fonctionné aussi, juste que je ne sais pas où mettre le paramètre boost. –

Répondre

0

J'ai finalement pensé à elle, la bonne syntaxe est la suivante:

curl -XPOST "http://localhost:9200/ind_ahor_fin_ult1/_search" -d' 
{ 
    "query": { 
     "bool": { 
      "should": [ 
       { "match": { "segmento": {"query":"02 - PARTICULARES","boost":2}}}, 
       { "match": { "renta": {"query":"1","boost":3}}} 
      ], 
      "minimum_should_match": 2 
     } 
    } 
}' 

Il a été très bien décrit sur:

https://www.elastic.co/guide/en/elasticsearch/guide/current/query-time-boosting.html

je l'avais manqué, en quelque sorte. Merci!