Skip to content

Indexing completion type fields with multi-fields fails #15115

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
underyx opened this issue Nov 30, 2015 · 5 comments · Fixed by #34081
Closed

Indexing completion type fields with multi-fields fails #15115

underyx opened this issue Nov 30, 2015 · 5 comments · Fixed by #34081
Labels
>bug good first issue low hanging fruit :Search Foundations/Mapping Index mappings, including merging and defining field types Team:Search Foundations Meta label for the Search Foundations team in Elasticsearch

Comments

@underyx
Copy link

underyx commented Nov 30, 2015

Edit: As it turns out, the issue I originally had was expected behavior, but it would be better if mappings like this would be rejected when someone tries to set them, so I'm leaving the original issue text below:

I'm trying to specify a field like this in 2.1.0:

...
"city": {
    "type": "completion",
    "preserve_separators": false,
    "payloads": true,
    "fields": {
        "analyzed": {
            "type": "completion",
            "analyzer": "standard",
            "payloads": true,
        }
    }
}
...

Indexing seems to be okay, but when searching, I get an error saying that "Field [city.analyzed] is not a completion suggest field". Am I wrong to expect this to work?

@underyx underyx changed the title Multi-fields on completion suggester not working Multi-fields on completion type field not working Nov 30, 2015
@clintongormley clintongormley added >bug :Search Foundations/Mapping Index mappings, including merging and defining field types labels Nov 30, 2015
@clintongormley
Copy link
Contributor

Hi @underyx

Completion fields shouldn't support multi-fields, because a completion field can accept a structured object which wouldn't work with (eg) a string subfield. I've marked this as a bug because we should complain about this at mapping time.

@underyx
Copy link
Author

underyx commented Nov 30, 2015

I see, thank you, @clintongormley!

@underyx underyx changed the title Multi-fields on completion type field not working Completion suggester fields don't error out when given multi-fields Nov 30, 2015
@clintongormley clintongormley added good first issue low hanging fruit help wanted adoptme labels Feb 14, 2016
@javanna
Copy link
Member

javanna commented Mar 16, 2018

@elastic/es-search-aggs

@pgomulka
Copy link
Contributor

pgomulka commented Sep 21, 2018

Hi,
I was trying to reproduce that issue with the oldest version supported 5.2.1 (same for the 6.4) , and it is not possible to index a document with a multi-field of completion type.

It is however still possible to create a mapping with multi-fields of type completion. Should this be prevented?

curl --request PUT \
  --url http://localhost:9200/cities \
  --header 'content-type: application/json' 
>>
{"acknowledged":true,"shards_acknowledged":true}
curl --request PUT \
  --url http://localhost:9200/cities/citytype/_mapping \
  --header 'content-type: application/json' \
  --data '
{
  "citytype" : {
        "properties" : {
            "city" : { 
                "type": "completion",
                            "preserve_separators": false,
                            "fields": {
                                    "analyzed": {
                                            "type": "completion",
                                            "analyzer": "standard"
                                    }
                            }
            }
        }
    }
}'
{"acknowledged":true}
curl --request PUT \
  --url http://localhost:9200/cities/citytype/1 \
  --header 'content-type: application/json' \
  --data '
{
    "city" : {
        "input": [ "Krak", "Cracow" ],
        "weight" : 34
    }
}’
>>
{
    "error": {
        "root_cause": [
            {
                "type": "parse_exception",
                "reason": "failed to parse expected text or object gotEND_OBJECT"
            }
        ],
        "type": "mapper_parsing_exception",
        "reason": "failed to parse",
        "caused_by": {
            "type": "parse_exception",
            "reason": "failed to parse expected text or object gotEND_OBJECT"
        }
    },
    "status": 400
}

See gist with curl requests and responses
https://gist.github.com/pgomulka/d3444a8ea93f0672392fb518aaacc839

@pgomulka pgomulka self-assigned this Sep 21, 2018
@pgomulka pgomulka removed the help wanted adoptme label Sep 21, 2018
@pgomulka pgomulka changed the title Completion suggester fields don't error out when given multi-fields Indexing completion type fields with multi-fields fails Sep 26, 2018
@pgomulka
Copy link
Contributor

pgomulka commented Sep 26, 2018

Creating documents on mappings with completion type fields with multi-fields fails when the document is provided with completion field in a form of array or object. This is because sub multi-field of different then completion type is not able to parse that format.

curl --request PUT \
  --url http://localhost:9200/citiesx2 \
  --header 'content-type: application/json' \
  --data '
{
  "mappings": {
    "citytype": {
      "properties": {
        "city": {
          "type": "completion",
          "preserve_separators": false,
          "fields": {
            "analyzed": {
              "type": "keyword"
            }
          }
        }
      }
    }
  }
}
'

curl --request PUT --url http://localhost:9200/citiesx2/citytype/12 --header 'content-type: application/json’ --data '
{
  "city" : {
        "input":["New york", "NY"],
        "weight": 34
    }
}
>>>
{
    "error": {
        "root_cause": [
            {
                "type": "mapper_parsing_exception",
                "reason": "failed to parse [city.analyzed]"
            }
        ],
        "type": "mapper_parsing_exception",
        "reason": "failed to parse [city.analyzed]",
        "caused_by": {
            "type": "illegal_state_exception",
            "reason": "Can't get text on a END_OBJECT at 6:2"
        }
    },
    "status": 400
}

Sub multi-field of type completion, fails due to reusing a context with a parser being already at the end of the object.

curl --request PUT \
  --url http://localhost:9200/subfieldcompletion \
  --header 'content-type: application/json' \
  --data '
{
  "mappings": {
    "citytype": {
      "properties": {
        "city": {
          "type": "completion",
          "preserve_separators": false,
          "fields": {
            "analyzed": {
              "type": "completion"
            }
          }
        }
      }
    }
  }
}
’

curl --request PUT \
  --url http://localhost:9200/subfieldcompletion/citytype/12 \
  --header 'content-type: application/json' \
  --data '
{
  "city"  : {
        "input": [ “New York", “NY" ],
        "weight" : 34
    }
}’
>>
{
    "error": {
        "root_cause": [
            {
                "type": "parse_exception",
                "reason": "failed to parse expected text or object gotEND_OBJECT"
            }
        ],
        "type": "mapper_parsing_exception",
        "reason": "failed to parse",
        "caused_by": {
            "type": "parse_exception",
            "reason": "failed to parse expected text or object gotEND_OBJECT"
        }
    },
    "status": 400
}

The issue was initially created to prevent mappings with completion type fields with multi-field. However we already support that, it works fine when indexing document with completion type field in String format.

curl --request PUT \
  --url http://localhost:9200/subfieldcompletion2/citytype/12 \
  --header 'content-type: application/json' \
  --data '
{
  "city"  : "New York"
}'

It is possible to fix that by modifying the CompletionFieldMapper to provide multiFields mapper with a context with already parsed externalValue. Also The CompletionFieldMapper itself, should support externalValues from context (it is not at the moment)
Will create a PR with a fix instead of validation shortly.

pgomulka added a commit to pgomulka/elasticsearch that referenced this issue Oct 1, 2018
Mappings with completion type and multi-fields, were not able to index array or
object format on completion fields. Only string format was supproted.
This is fixed by providing multiField parser with externalValueContext with already parsed object

closes elastic#15115
pgomulka added a commit that referenced this issue Oct 2, 2018
Mappings with completion type and multi-fields, were not able to index array or
object format on completion fields. Only string format was supported.
This is fixed by providing multiField parser with externalValueContext with already parsed object

closes #15115
pgomulka added a commit to pgomulka/elasticsearch that referenced this issue Oct 2, 2018
Mappings with completion type and multi-fields, were not able to index array or
object format on completion fields. Only string format was supported.
This is fixed by providing multiField parser with externalValueContext with already parsed object

closes elastic#15115
pgomulka added a commit that referenced this issue Oct 3, 2018
)

Mappings with completion type and multi-fields, were not able to index array or
object format on completion fields. Only string format was supported.
This is fixed by providing multiField parser with externalValueContext with already parsed object

* Adapt test after backport of #34081

closes #15115
kcm pushed a commit that referenced this issue Oct 30, 2018
Mappings with completion type and multi-fields, were not able to index array or
object format on completion fields. Only string format was supported.
This is fixed by providing multiField parser with externalValueContext with already parsed object

closes #15115
@javanna javanna added the Team:Search Foundations Meta label for the Search Foundations team in Elasticsearch label Jul 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>bug good first issue low hanging fruit :Search Foundations/Mapping Index mappings, including merging and defining field types Team:Search Foundations Meta label for the Search Foundations team in Elasticsearch
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants