эластичный поисковый DSL-запрос python для строковых типов

Я очень старался, но изо всех сил пытался понять это правильно. На самом деле в моем отображении индекса все мои поля представляют собой строки типа. например

{"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"}}}}}}

Я, используя клиент python для elasticsearch, сгенерировал следующий запрос:

{'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}}}]}}}

Однако я получаю это исключение, даже если я пытаюсь использовать любой термин массива в «следует»:

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}

пожалуйста помоги. ТИА.


person Sumit Khanna    schedule 03.12.2016    source источник
comment
запрос диапазона работает нормально, просто эти запросы строкового типа не   -  person Sumit Khanna    schedule 03.12.2016
comment
curl -XPOST localhost:9200/ind_ahor_fin_ult1/_search -d' {запрос: {bool: { должен: {match:{segmento:02 - PARTICULARES}},boost: 1}}}', дай мне посмотреть, смогу ли я сшить массив тоже в   -  person Sumit Khanna    schedule 03.12.2016
comment
curl -XPOST localhost:9200/ind_ahor_fin_ult1/_search -d' { query: { bool: { must: [ { match: { segmento: 02 - PARTICULARES }}, { match: {renta: 1 }} ] } } }' Это тоже сработало, просто я не знаю, куда поместить параметр boost.   -  person Sumit Khanna    schedule 03.12.2016


Ответы (1)


Я, наконец, понял это, правильный синтаксис ниже:

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
        }
    }
}'

Очень хорошо описано на:

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

Я как-то пропустил это. Спасибо!

person Sumit Khanna    schedule 03.12.2016